pythonhoudini

How to get node parameter in Houdini with Python


I am very much new to Houdini and this might be something very obvious to ask but I have hit a brick wall. I would like to store a parameter, specifically the File Name of an alembic object so that I can validate the filename to see if it follows a namespace convention

Property I am trying to get circled in red

The following is all I have

import hou

node = hou.node('obj/alembic1/alembic1')

after getting the node, how would I get the File Name property? Any guidance is greatly appreciated


Solution

  • There's two main ways:

    1 As you you've started to do in your code, access the node then access the parm HOM method of Node:

    parm = hou.node('obj/alembic1/alembic1').parm('fileName')
    

    2 Use hou.parm directly:

    parm = hou.parm('obj/alembic1/alembic1/fileName')
    

    parm is an object representing a parameter, to get the value of the parameter you need to call it's eval method:

    parmval = parm.eval() 
    

    So something like this is the usual case:

    node = hou.node('obj/alembic1/alembic1')
    parmVal = node.parm('fileName').eval()
    

    Note that parm.eval() will work for most cases, but sometimes you might need more verbose methods such as parm.evalAsNode(). Check out the help here.

    You can see the parm name to use in your code when you hover over the parameter name you want to access in the parameters window. Ie if you hover over "File Name" in the Alembic node it will show:

    Parameter: fileName