Event Handlers in HDA

   6811   5   1
User Avatar
Member
183 posts
Joined: Nov. 2008
Offline
Hi. Please help me with this problem:

I have PreFirstCreate event, in HScript:
omsbind -t sop polyExtract:group prims “Poly selector” “This is HScript event!” 0 1 face 0 “” 0

Ok, it works. Then i decided, to do it in Python:
kwargs.addSelector(“polySelector”,“prims”,
prompt=“This is Python event!”)

And here interesting thing happens Even if change this event to from HScript to Python, when i use my tool in viewport, it still executes HScript event! Of course i'm saving all changes.I'm also doing File -> Refresh Asset Libraries. The only thing that helped me - recreate asset, without PreFirstCreate event.
And vice versa, if PreFirstCreate event was in Python, and i change it to HScript, it will still call Python, even if i delete this event!
Any Ideas???
Aleksei Rusev
Sr. Graphics Tools Engineer @ Nvidia
User Avatar
Member
1908 posts
Joined: Nov. 2006
Offline
Changing the script and refreshing the libraries isn't going to help in the case of a script that is being run before the first creation of the asset. If you have had an instance of that node in your current session then that script is no longer being run. You will have to relaunch Houdini for changes to PreFirstCreate to take affect.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
183 posts
Joined: Nov. 2008
Offline
graham
Changing the script and refreshing the libraries isn't going to help in the case of a script that is being run before the first creation of the asset. If you have had an instance of that node in your current session then that script is no longer being run. You will have to relaunch Houdini for changes to PreFirstCreate to take affect.

Thx graham, but the funny thing is that i have tryed everything (and Houdini restart, and saving in different otl name, jumping through definitions back and forth ….).

If you have had an instance of that node in your current session then that script is no longer being run
why not? if i make a selector, it will ask for selection every time i create new instance…
Maybe using PreFirstCreate event to prompt user to make selection isn't the best way to do it??
What is a better way to do it? Let me clarify, what i want to get:
I need to be able to make polygon selection in viewer, this selection then go to my “group” parameter, then an instance of my node should be created, and based on selection, inside my asset, there are some computation, that i need to use as initial state for some parms in asset.
I have a OnCreated event, and there is some simple code:
pivotValue = kwargs.geometry().attribValue('myPivot')
kwargs.parmTuple('p').set(pivotValue)
This code should execute after my node creation, and after my node cooks. How can i accomplish this?? I always get error, that says: bla bla bla, None has no method attribValue()…. This means , that my geometry() returns None. Why? I think because scripts get executed before my sop cooks…. So, what wrong?
Aleksei Rusev
Sr. Graphics Tools Engineer @ Nvidia
User Avatar
Member
1908 posts
Joined: Nov. 2006
Offline
What I mean is that the PreFirstCreate script gets run once, before you create a node of that type in a session for the first time. If you put down your node, then change the contents of that script it won't take effect until the next time it will be run, in a new session.

What you are doing when you are adding a selector is associating a selection event to your node type. When you create a SOP node, unless you have written custom tool code, Houdini is going to run the generic tools and try to determine if it needs to select any geometry. By default it attempts to make selections based on any attached hou.Selector objects. These are what you are adding when you call hou.SopNodeType.addSelector in that event handler. No selections actually occur when this happens. It just primes it up for later use.

As for your other issue with setting parameter values based on cooked node, that would require more custom tool code as by default Houdini's tools do things differently.

As I mentioned before, the OnCreated code always gets called immediate upon creation, not after your node has been created and cooked. There is not really any easy way to defer this without writing more custom code. You can call hou.Node.createNode() and pass an argument to not run init scripts, aka OnCreated, but you can't really do that unless you write your own code. Another problem is the fact that your node requires an input. That's what causes attempting to force cook inside the event to fail as well. The new node is not even connected to its input node until sometime after the event handler is run. To me, if you really need to do something like this you'll have to do a new tool script for your asset. It would need to do a bit different ordering of things.

You'd need to perform selections manually, or at least call some code from soptoolutils to do it. You could then create the node using a soptoolutils then transfer any selection stuff to your group parm. Alternatively you could still use the selectors you are trying to add to do this. Once your node is all hooked up and ready you should then be able to force cook it and get the result and your parm values. You could then set the parm values on your node and that would be the end of the tool.

Doing this you wouldn't actually need to use an OnCreated event. You could also have it setup so all the fancy things happens only when creating the node from the shelf/viewer, or anything else you'd like to do.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
183 posts
Joined: Nov. 2008
Offline
Thank you very much graham. Now i understand things clearly
I'll try to write custom tool script with soptoolutils. I'll be back soon, with new questions.
Thx for help.
Aleksei Rusev
Sr. Graphics Tools Engineer @ Nvidia
User Avatar
Member
3 posts
Joined: Dec. 2016
Online
Hi,

I have an HDA (sop) that contains a different HDA (rop). The problem I have is that I need both of them to run a OnCreated event, but it seems to run only when user creates the node, not when it gets created as a part of a different hda (both have the OnCreated working, when I just create them separatelly).

Does anyone have a solution for this?

Thanks
Martin

Running: Houdini 17.5, Linux
  • Quick Links