Python reference to its own operator

   7867   8   1
User Avatar
Member
1390 posts
Joined: July 2005
Offline
I really don't understand how should I refer to an operator (HDA) from within scripts inside it (both from “Extra Files” and “Scripts” section).

When I call PythonModule's function I have to send it reference by hand since I didn't find any other solution:

hou.pwd().hdaModule().main(hou.pwd().path())

but this is crazy of course! There must be a “normal” way. This also doesn't work with “onInputChanged” script as I can't send any variable like before.

In both cases hou.pwd() returns context carrying operator (/out) not a operator itself.

thanks for help.
sy.
User Avatar
Member
11 posts
Joined: Oct. 2007
Offline
In a callback script on an hda you can do something like

hou.node('.')

to refer to ‘self’…I think that is what you are looking for.
User Avatar
Member
1390 posts
Joined: July 2005
Offline
hmm… not really, this was the first thing I've checked.
Unfortunately this returns /out instead of /out/my_operator

I've already found my old post on the same subject… strange but few months ago I was struggling with the same topic.

I was told that in case of hscript, a script in hdaModule (onCreate for example) gets reference by argument $arg1.
But I don't know how to send to python…

still looking,
thanks,
sy.
User Avatar
Member
401 posts
Joined:
Offline
hm.
I tried this at home:
a button that executes this script:
hou.ui.displayMessage(str(hou.pwd()) + “\n” + str(hou.node(“.”)))
And both point to the correct node.

Just yesterday I used hou.pwd() in my callbackscript and it worked just fine.

Georg
this is not a science fair.
User Avatar
Member
1390 posts
Joined: July 2005
Offline
you,re right. Callback script is not a problem. You can send it attribute.
Try to reference like this in “onCreate” or “onInputChanged” script .
Well, can't be done
User Avatar
Member
1904 posts
Joined: Nov. 2006
Offline
Since python event handlers are currently not supported in 9, using $arg1 to get the path of the new node is the correct thing to do. You could do something like this.

python -c “hou.node('$arg1').hdaModule().main('$arg1')”
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Staff
270 posts
Joined: July 2005
Offline
Note that Python event handlers are supported in later versions of 9.0. The node is available via kwargs. So it would be something like:

node = hou.node(kwargs)
node.hdaModule().main(node)
User Avatar
Member
1904 posts
Joined: Nov. 2006
Offline
Oops. I forgot they were back ported

kwargs returns a node object so it should be

node = kwargs
node.hdaModule().main(node)
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
1390 posts
Joined: July 2005
Offline
O! Thank you!

happy, happy I am.

cheers,
sy.
  • Quick Links