set param through python

   21082   5   1
User Avatar
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
User Avatar
Member
74 posts
Joined: Dec. 2009
Offline
maybe

expression = “strmatch(chs(”../object_merge1/objpath1“), ”“)”
path = “.” //path of the node you intended to set the parm
hou.node(path).parm(“input”).setExpression(expression)
https://www.linkedin.com/in/kelvincai/ [www.linkedin.com]
User Avatar
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)
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
121 posts
Joined: July 2008
Offline
Hey guy's I'm just getting into python so thank you very much.
This explains a great deal for me.

Also I'm working on OSX, is there any way to get an error pop-up window like you get on windows. Because without it debugging is a bit hard.
Available for new projects
User Avatar
Member
19 posts
Joined: March 2010
Offline
start your houdini from the command line (go to houdini-> houdini.shell) and start houdini that way. you'll get all your errors in the shell.
User Avatar
Member
121 posts
Joined: July 2008
Offline
whoehoe!!!
Works like a charm.
Cheers man
Available for new projects
  • Quick Links