python script on Created

   6520   6   1
User Avatar
Member
509 posts
Joined: July 2005
Offline
Hi all,

I'm having trouble finding a way to make my HDA to run some code when I create a new instance of the tool..

I tried the onLoaded and onCreated but it seems they get ignored.
I also tried the tools/script … but it didn't work either.

I'm trying to change the asset's color in this case and I'd like to do it using python.

thanks in advance!
JcN
VisualCortexLab Ltd :: www.visualcortexlab.com
User Avatar
Member
1906 posts
Joined: Nov. 2006
Offline
Are your scripts name and located correctly?

You should put your OnCreated.py or OnLoaded.py in a scripts/ directory somewhere in the HOUDINI_PATH. For example, $HOME/houdiniX.Y/scripts/OnCreated.py
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
509 posts
Joined: July 2005
Offline
I'm using the HDA type properties->scripts->event handler page to write code into, not an external py file.
JcN
VisualCortexLab Ltd :: www.visualcortexlab.com
User Avatar
Member
1906 posts
Joined: Nov. 2006
Offline
Are they still named correctly though?
onLoaded and onCreated
aren't the correct section names. Also, are they set to Python?
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
509 posts
Joined: July 2005
Offline
yep, houdini creates such sections when I select any of those..
and yeah sorry.. correct names are “OnLoaded” or “OnCreated” .. and set to python.

it seems I've found the problem.
in fact the code is working.. but its coloring “its parent” ..

if I run the following code:

node = hou.pwd()
color = hou.Color()
color.setRGB((0.4,0.2,0.6))

node.setColor(color)


in a SOP hda->OnCreated script, the containing OBJ will get such color.

isn't hou.pwd() supposed to be the SOPhda itself?

thanks!
JcN
VisualCortexLab Ltd :: www.visualcortexlab.com
User Avatar
Member
1906 posts
Joined: Nov. 2006
Offline
No. The parent has to create the node as a child, so pwd() will return it. You get the newly created node using kwargs
node = kwargs
node.setColor(hou.Color((1,0,0)))
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
509 posts
Joined: July 2005
Offline
graham
No. The parent has to create the node as a child, so pwd() will return it. You get the newly created node using kwargs
node = kwargs
node.setColor(hou.Color((1,0,0)))


ahh that's it! thanks a lot! exactly what I needed
I remember reading about that kwargs but I guess I need to investigate further more on that one.

thanks!
JcN
VisualCortexLab Ltd :: www.visualcortexlab.com
  • Quick Links