How to use Python to set expression to reference a channel

   2424   3   2
User Avatar
Member
4 posts
Joined: 3月 2019
Offline
Hi,
I ran into a problem with using Python setExpression() function to reference a string channel.
For float and integer parameters it works fine. However, only the string parameter couldn't work.

Here are the examples I did.

First attempt:
dens_newname.parm('frompt0').setExpression('chs("../custom_density")', language=hou.exprLanguage.Hscript)
Second time I copy and paste the parameter as a relative reference, then I copy `chs("../custom_density")`
dens_newname.parm('frompt0').setExpression('`chs("../custom_density")`', language=hou.exprLanguage.Hscript)
None of them work.

If anyone has a solution for this, please let me know.
User Avatar
Member
191 posts
Joined: 10月 2018
Offline
What's not working? The first one looks correct, but you could try without the language argument because it will default to hscript anyway.

You can also try your last attempt just using set() instead of setExpression() ie:
dens_newname.parm('frompt0').set('`chs("../custom_density")`')
User Avatar
Member
4 posts
Joined: 3月 2019
Offline
mkps
What's not working? The first one looks correct, but you could try without the language argument because it will default to hscript anyway.

You can also try your last attempt just using set() instead of setExpression() ie:
dens_newname.parm('frompt0').set('`chs("../custom_density")`')

Thanks for replying.
I end up using set() instead of setExpression(), and it got to work. I didn't really know the reason why setExpression() couldn't work.
User Avatar
Member
1 posts
Joined: 11月 2017
Offline
you should use (dens_newname.parm('frompt0').set('chs("../custom_density")', language=hou.exprLanguage.Hscript))
  • Quick Links