python inception?

   859   1   1
User Avatar
Member
25 posts
Joined: Jan. 2014
Offline
Hey there guys.

I have a quick question.

I am trying to make a shelf tool at the obj level to automate some processes to go through my scene, collect some info, and at the end of the day create a new geo node, and python sop node within it. I then want this script to insert code into it that python sop.

If anyone has any links with info on how to do this it would be appreciated.

I think I came by a site a few weeks ago when I was looking for other info that had listed a way on how to create a point wrangle and auto insert code into it, but at the moment I am hoping on using python for this exercise.

Any help would be appreciated.
Cheers.
Edited by Martin Krol - March 17, 2021 14:13:24
User Avatar
Member
191 posts
Joined: Oct. 2018
Offline
Are you only looking for help with creating the geo node and python sop? This will do that:

# Get the root obj node
parentNode = hou.node("/obj")
# Create a new geo node under the parent node
geoNode = parentNode.createNode( "geo", "some_geo_node" )
# Create a python sop under the geo node
pythonNode = geoNode.createNode( "python", "some_python_node" )
# Get the python code parameter from the python sop
codeParm = pythonNode.parm("python")
# Create the python code as a string value
code = "foo = 'bar'\n\nprint foo"

# Set the python code parameter to the python code string value
codeParm.set( code )

If your python code going into the python sop gets complicated, it might be easier to save a preset for the python sop and assign that instead of trying to set the python code parameter.

hou.hscript( "oppresetload %s '%s'" % ( pythonNode.path(), "Some Saved Preset Name" ) )
Edited by krueger - March 17, 2021 17:55:52
  • Quick Links