how to set a channel reference in a Python script?

   2746   3   1
User Avatar
Member
47 posts
Joined: July 2014
Offline
I'm trying to set a channel reference by entering a string in a set operation:

transformnode = hou.node('obj/track').createNode('xform', “transform” + str(minmaxspeedindexpoint))
transformnode.parm('px').set('ch(“../font' + str(x) + ‘/tx”)’)

but it's complaining that I can't set a numerical value to a non-numerical value.
User Avatar
Member
806 posts
Joined: Oct. 2016
Offline
Moin,

what's “x”? If it is undefined, it's definitely a non-numerical value (note that you are escaping from your quote in the parm().set() sequence, probably intentionally so).

One way to debug something like this is to set variables you use manually in a python shell (Houdini offers that conveniently) and step by step recreating the expression until you get the error. Then the last step/change you made is the culprit.


Marc
---
Out of here. Being called a dick after having supported Houdini users for years is over my paygrade.
I will work for money, but NOT for "you have to provide people with free products" Indie-artists.
Good bye.
https://www.marc-albrecht.de [www.marc-albrecht.de]
User Avatar
Member
8521 posts
Joined: July 2007
Online
you nees to use .setExpression() instead of .set()
transformnode = hou.node('obj/track').createNode('xform', "transform" + str(minmaxspeedindexpoint))
transformnode.parm('px').setExpression('ch("../font' + str(x) + '/tx")')
you can also use string formatting to build your strings
transformnode = hou.node('obj/track').createNode('xform', "transform{}".format(minmaxspeedindexpoint))
transformnode.parm('px').setExpression('ch("../font{}/tx")'.format(x))
or the old string formatting, not sure whether that's being phased out or not, but for now may be shorter sometimes
transformnode = hou.node('obj/track').createNode('xform', "transform%d" % minmaxspeedindexpoint)
transformnode.parm('px').setExpression('ch("../font%d/tx")' % x)
Edited by tamte - April 4, 2020 18:58:56
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
47 posts
Joined: July 2014
Offline
thanks. setExpression works.
  • Quick Links