spawning a custom amount of nulls based off of integer value

   897   1   1
User Avatar
Member
7 posts
Joined: Sept. 2016
Offline
I'm trying to build an asset builder where I prep the assets in sops and then in LOPS set up the different variants etc.

I want to automate some of the shader setup, and if an asset contains multiple shaders/mats I've set up a script to spawn an integer value based off of the unique amount of @shop_matpaths

However I for some reason CANNOT make it work. If I just try to spawn a null by pressing my custom button it works fine, but as soon as I want it to spawn multiple nulls based off of my value it doesn't react or call for an error or whatever

Here's the code that actually works and spawns a single null

import hou

def create_null_nodes(parent_node):
# Create a new null in the LOP context
for selected_node in hou.selectedNodes():
dir = selected_node.parent().path() + '/'
other_name = hou.ui.readInput('Name the null', buttons'OK', 'CANCEL'), initial_contents='_')
nullnode = hou.node('/%s' % dir).createNode('null', 'OUTPUT%s' % other_name)
sel_node_pos = selected_node.position()
nullnode.setColor(hou.Color())
nullnode.setPosition(hou.Vector2(sel_node_pos, sel_node_pos - 1))
nullnode.setInput(0, selected_node)
selected_node.setSelected(False)
nullnode.setSelected(True)
try:
nullnode.setDisplayFlag(True)
nullnode.setRenderFlag(True)
except:
nullnode.setDisplayFlag(True)

# Callback script
lopnet_node = hou.node('/stage/asset_builder')
create_null_nodes(lopnet_node)

And here's my code when I try to run it a little differently, when I want it to spawn a custom amount

import hou

def create_null_nodes(parent_node, material_count):
for i in range(material_count):
node_name = "shader_builder_{}".format(i + 1)
new_null_node = parent_node.createNode("null", node_name)
new_null_node.setDisplayFlag(True)
new_null_node.setRenderFlag(True)

# Position the null node
if i > 0:
prev_node = parent_node.node("shader_builder_{}".format(i))
prev_node_pos = prev_node.position()
new_null_node.setPosition(hou.Vector2(prev_node_pos, prev_node_pos - 1))

# Callback script
node = hou.pwd()
material_count = node.parm('material_count').eval()

lopnet_node = hou.node('/stage/asset_builder')
create_null_nodes(lopnet_node, material_count)

Does anybody have any clue?

I'm not much of a technical artist, but I'd just love to automate much of the USD asset generation process and I find the component builder in it of itself to be a little lacking

I've attached a photo of my setup. The code is supposed to run when I press the complex shader setup button (complex cuz there's multiple materials instead of being just 1 asset with 1 overall mat)

Attachments:
usd_asset_builder2.png (969.5 KB)

User Avatar
Member
44 posts
Joined: March 2023
Offline
why not just create a material network and create new materials inside and link them to the correct geometry ? with python ?

Why use the null`s at all ?
  • Quick Links