Jump to content

Setting an expression as default value. (SOLVED)


Jan_red

Recommended Posts

Hello All,

Is it possible to set an expression as a default value on a int or float while creating a paramTemplate.

At the moment i am trying to set the default value through the default_value argument. Unfortunately this creates an error as it expects an float/int.

So far the only way I have found is setting the expression after the ui has been created.

Example code:

This works fine! But I have to first apply the parm template before being allowed to turn it into an expression.

(which i preferbly do not want to do)

>>> obj = hou.node('obj')
>>> geo = obj.createNode('geo')
>>> null = geo.createNode('null')
>>> parmTemplateGrp = null.parmTemplateGroup()
>>> # here we create our float parm template
>>> hou_parm_float = hou.FloatParmTemplate("expressionTest", "works", 1, default_value=([0]), look=hou.parmLook.Regular, naming_scheme=hou.parmNamingScheme.Base1)

>>> parmTemplateGrp.append(hou_parm_float)
>>> null.setParmTemplateGroup(parmTemplateGrp)
>>> myParm = null.parm('expressionTest')
>>> myParm.setExpression('$TX')

This errors out. As it expects a value.


>>> hou_parm_float = hou.FloatParmTemplate("expressionTest", "fails", 1, default_value=(["$TX"]), look=hou.parmLook.Regular, naming_scheme=hou.parmNamingScheme.Base1)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.623/houdini/python2.6libs\hou.py", line 13723, in __init__
    this = _hou.new_FloatParmTemplate(*args, **kwargs)
TypeError: in method 'new_FloatParmTemplate', argument 4 of type 'std::vector<double,std::allocator<double > > const &'

Does anyone have any ideas on how to solve this one ?

Thanks!

Jan

Edited by Jan_red
Link to comment
Share on other sites

  • 1 month later...

Solved!!(noting it down for future reference)

The houdini support has been kind enough to help me out on this one and apparently the documentation was outdated and there is a keyword called default_expression (which totally makes sense) that can be used:

# Create a float parameter template with "$F" as the default Hscript expression
# for each of the components.
parm_template = hou.FloatParmTemplate("my_parm", "My Parm", 3, default_expression=("$F", "$F", "$F"), default_expression_language=(hou.scriptLanguage.Hscript, hou.scriptLanguage.Hscript, hou.scriptLanguage.Hscript))

# Print the default expression and language.
print parm_template.defaultExpression()
print parm_template.defaultExpressionLanguage()

# Set the default expression and language to something else.
# Unset the default expression for the 3rd component.
parm_template.setDefaultExpression(("$F", "hou.frame()", ""))
parm_template.setDefaultExpressionLanguage((hou.scriptLanguage.Hscript, hou.scriptLanguage.Python, hou.scriptLanguage.Hscript)) 

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