Dynamic creation of Tops nodes / connections

   541   0   1
User Avatar
Member
2 posts
Joined: July 2020
Offline
Hey all,

Playing around with PDG. One of the big concerns for our team is to be able to dynamically create / edit node networks in a declarative, text driven way. Think ansible playbooks or other CI/CD solutions. ( yaml etc )

So far, I am able to create nodes, but connecting them seems to error out.

A brief description of what I am trying to do:
iterate over nested python dictionaries to create, connect and set parms on PDG nodes

I did a brief test as follows:

  • create a topnet
  • jump inside
  • create a pythonscript node
  • set pythonscript "Evaluate Script During" to Generate


Then paste this script in the pythonscript node script section:

# Executes a Python script, either in process or as a job
#
# The following variables and functions are available in both case:
# work_item
# intData, floatData, strData,
# intDataArray, floatDataArray, strDataArray
#
# In addition to the above, in-process scripts can also access:
# self - the current PDG node
# parent_item - the parent work item, if it exists
import hou

topnet_path = '/obj/topnet1'

# Here is my node structure
data = {'my_node_1':{'type':'pythonscript'},
'my_other_node': {'type':'pythonpartitioner'}
}

# get the topnet
topnet = hou.node(topnet_path)

# store an array of output nodes
new_nodes = []

# get the root python script node ( this node )
# this will connect it's output to the input of the created nodes
root_python_script_path = '/obj/topnet1/pythonscript1'
root_python_script_node = hou.node(root_python_script_path)

# iterate over the data
for node_name, node_data in data.items():
new_node = None

node_type = node_data.get('type')

if not topnet:
raise RuntimeError('Could not find node: {}'.format(node_type))
else:
new_node = topnet.createNode(node_type, node_name, 0)


# !!!!!!!!!!!!!! here is where it fails
if new_node:
new_node.setInput(0, root_python_script_node)

new_nodes.append(new_node)



# clean up the layout
topnet.layoutChildren()


# report back
print('\n\n')

print('Created New Nodes:')
print('~'*120)
for node in new_nodes:
print('\t"<{}>: {}"'.format(new_node.type(), new_node.path()))

print('\n')
print('~'*120)

However, when I get an
hou.OperationFailed
at the
new_node.setInput()


If I move the connection out of the loop, Houdini straight up locks and closes.

Any thoughts? I assume that the graph population is happening without updating, so the inputs are not yet available when trying to connect things.


Another thing I noticed, if I get a failure... then comment out the failed line.. and run it again... houdini will create 4 nodes. 2 for each loop. Effectively, it is internally holding onto the python data between runs.


Any help is appreciated

-s
Edited by speters - July 23, 2021 14:29:37
  • Quick Links