Jump to content

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


LaidlawFX

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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

  • 4 years later...
On 11/15/2016 at 4:29 AM, Atom said:

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())

 

Just what i was looking for! How can you remove parameters??

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...