set param through python
21081 5 1- claudio_101
- Member
- 121 posts
- Joined: July 2008
- Offline
expression = setExpression(“strmatch(chs(”../object_merge1/objpath1“), ”“)”, exprLanguage.Hscript)
^
SyntaxError: invalid syntax
Switch.parm(“input”).set(expression)
Hey guy's, I'm trying to get some code into a parameter through python.
Any suggestion on why this is going wrong.
thx
Available for new projects
- kelvincai
- Member
- 74 posts
- Joined: Dec. 2009
- Offline
- graham
- Member
- 1908 posts
- Joined: Nov. 2006
- Offline
A couple things.
First off, setExpression() isn't a standalone function. It is only a method available through instances of hou.Parm. So as kelvincai suggests you'll want to either create your expression as a string and pass it to hou.Parm.setExpression(), or just enter it directly as the expression text.
The other issue is that your expression is formatted incorrectly in the sense that it is a string so you need to wrap it in quotes, but you have wrapped it with the same kind of quotes are in your expression itself. This will leave to problems since Python will see it as “strmatch(chs(”, some weird code, then another string of “), ” and another “)”. You'll either want to wrap it in single quotes ‘', or escape the quotes in the expression itself.
You also don’t really need to pass exprLanguage.Hscript unless your node has it's default scripting mode set to Python.
expression = ‘strmatch(chs(“../object_merge1/objpath1”), “”)’
or
expression = “strmatch(chs(\”../object_merge1/objpath1\“), \”\“)”
Switch.parm(“input”).setExpression(expression)
First off, setExpression() isn't a standalone function. It is only a method available through instances of hou.Parm. So as kelvincai suggests you'll want to either create your expression as a string and pass it to hou.Parm.setExpression(), or just enter it directly as the expression text.
The other issue is that your expression is formatted incorrectly in the sense that it is a string so you need to wrap it in quotes, but you have wrapped it with the same kind of quotes are in your expression itself. This will leave to problems since Python will see it as “strmatch(chs(”, some weird code, then another string of “), ” and another “)”. You'll either want to wrap it in single quotes ‘', or escape the quotes in the expression itself.
You also don’t really need to pass exprLanguage.Hscript unless your node has it's default scripting mode set to Python.
expression = ‘strmatch(chs(“../object_merge1/objpath1”), “”)’
or
expression = “strmatch(chs(\”../object_merge1/objpath1\“), \”\“)”
Switch.parm(“input”).setExpression(expression)
Graham Thompson, Technical Artist @ Rockstar Games
- claudio_101
- Member
- 121 posts
- Joined: July 2008
- Offline
- larsvdb
- Member
- 19 posts
- Joined: March 2010
- Offline
- claudio_101
- Member
- 121 posts
- Joined: July 2008
- Offline
-
- Quick Links