Welcome to od|forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

garf

Python - Parameters 'Type'

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

Share this post


Link to post
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.')

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thanks chaps - so added to this, is there a way to determine which language is used in the expression e.g. Python/Hscript or is it simply a case of interrogating the code to determine what it is?

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