Jump to content


Setting an expression as default value. (SOLVED)


  • Please log in to reply
1 reply to this topic

#1 Jan_red

Jan_red

    Peon

  • Members
  • Pip
  • 12 posts
  • Joined: 14-February 11
  • Name:Jan P

Posted 20 May 2012 - 10:41 AM

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, 20 June 2012 - 02:55 PM.


#2 Jan_red

Jan_red

    Peon

  • Members
  • Pip
  • 12 posts
  • Joined: 14-February 11
  • Name:Jan P

Posted 20 June 2012 - 02:55 PM

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users