Jump to content
LaidlawFX

Build list of a certain type of parameter on a node.

Recommended Posts

I'm trying to build a list of all the parameters of a certain type from a node in python.

For instance for a geo node, I want to build a list of all the toggle parameters on it.

Comparing hou.node('/obj/geo1').asCode() and hou.node('/obj/geo1').parms() was going down a very messy road. I was hoping there was a way to use just the .parms() and check if each parameter is a toggle type?

*Edit

I feel like this may have something to do with it, https://www.sidefx.com/docs/houdini15.5/hom/hou/ToggleParmTemplate

However only when I add a spare parameter and run .asCode() does it seem to reference this, and I can compare against .parms(), but it doesn't work on regular parameters.

Edited by LaidlawFX

Share this post


Link to post
Share on other sites
toggles = [p for p in node.parms() if p.parmTemplate().type() == hou.parmTemplateType.Toggle]
toggles = [p for p in node.parms() if isinstance(p.parmTemplate(), hou.ToggleParmTemplate)]

Not sure which is better.

  • Thanks 1

Share this post


Link to post
Share on other sites

Wow F1, only 8 minutes apart.^_^

You can fetch the parm type using code like this.

p = node.parm("parm_test")
pt = p.parmTemplate()
print pt.type()

Or maybe even more scanning of the node like this.

node = hou.pwd()
node_path_to_self = "/obj/pythonscript1"

# Add code to modify contained geometries.
# Use drop down menu to select examples.

lst_types = []
lst_toggles = []
lst_floats = []

def returnParmType(passedParm):
    t = passedParm.parmTemplate().type()
    return str(t)

def addToToggles(node_path,parm_name):
    lst_toggles.append((node_path, parm_name))

def addToFloats(node_path, parm_name):
    lst_floats.append((node_path, parm_name))

for p in node.parms():
    s = returnParmType(p)
    # Also support String, Int, Menu
    if s.find("Float") != -1: addToFloats(node_path_to_self, p.name())
    if s.find("Toggle") != -1: addToToggles(node_path_to_self, p.name())

 

Edited by Atom

Share this post


Link to post
Share on other sites
18 minutes ago, f1480187 said:

toggles = [p for p in node.parms() if p.parmTemplate().type() == hou.parmTemplateType.Toggle]
toggles = [p for p in node.parms() if isinstance(p.parmTemplate(), hou.ToggleParmTemplate)]

Not sure which is better.

Your my hero... and don't ever change.

Thanks so much.

*Edit: Atom you can belong in my extended hero universe ;)

Edited by LaidlawFX
Atom

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×