Jump to content

Python - Parameters 'Type'


garf

Recommended Posts

Ayup!

How do you evaluate a parameter to determine it's contents 'type' - e.g. expression/string - 'type' method is currently crossed out in the docs

http://www.sidefx.com/docs/houdini/hom/hou/Parm

 

import hou

sel = hou.selectedNodes()

for i in range(len(sel)):
    for p in range(0, len(sel[0].parms())):
        sel[1].parms()[p].set(sel[0].parms()[p].eval())
        print str(sel[0]) + ' = ' + str(sel[0].parms()[p].eval())
        print str(sel[1]) + ' = ' + str(sel[1].parms()[p].eval())

Link to comment
Share on other sites

It will return hou.parmTemplateType value, which is not exactly "expression/string" information. I think you can use this to get same result:

parm.parmTemplate().type()

Not sure if there is a better method, but you can check for expression like this:

try:
    parm.expression()
except hou.OperationFailed:
    print('Not expression branch.')
else:
    print('Expression branch.')

 

  • Like 1
Link to comment
Share on other sites

above should work on numerical parms, once that is determined and for string parms you could try something like....

 

is_exp=False

raw = parm.unexpandedString()

if any(['`' in raw, '$' in raw, '(' in raw]):

    is_exp = True

 

or some variation depending on exaxtly what other than string literal you are trying to detect

Link to comment
Share on other sites

  • 2 months later...

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...