Node pasted event callback?

   798   7   2
User Avatar
Member
185 posts
Joined: March 2011
Online
Hi,

I'm doing some hdas for pipeline stuff, and I need to run some python code when a node is created. It works well when the node is created but not when It's copied and pasted (by ctrl+c->ctrl+v or alt drag). Since a new node is being created, shouldn't the onCreated callback be called in the situation or I am missing something here?

I haven't found any suitable callback either.
User Avatar
Member
1814 posts
Joined: Nov. 2006
Online
Unless things have changed in recent versions, unfortunately there's no proper form of callbacks to easily tap into in regards to network editor actions which means you're pretty much forced to implement it on your own via a custom node graph event handler similar to this:

https://github.com/captainhammy/Houdini-Toolbox/blob/master/houdini/python3.7libs/nodegraphhooks.py [github.com]

It's been a while since I messed with any of that stuff and mostly don't recall how it works anymore. That file basically registers a custom handler that will do certain things otherwise defers the default Houdini handler. I believe that due to the way the default Houdini handler stuff was implemented it was pretty much impossible to just call their code while adding in your own hooks so it required making a copy of a bunch of the Houdini code to handle the actual pasting the way they do (nodegraph.handle_houdini_paste_event) and then eventually doing something that you want to do, which in this case was me emitting a callback for my own crappy callback system.

I recall it was a bit of a pain to figure out and a lot of diving into various places but we eventually figured out something that worked well enough for our goals.
Graham Thompson, Pipeline Things
User Avatar
Member
185 posts
Joined: March 2011
Online
graham
Unless things have changed in recent versions, unfortunately there's no proper form of callbacks to easily tap into in regards to network editor actions which means you're pretty much forced to implement it on your own via a custom node graph event handler similar to this:

https://github.com/captainhammy/Houdini-Toolbox/blob/master/houdini/python3.7libs/nodegraphhooks.py [github.com]

It's been a while since I messed with any of that stuff and mostly don't recall how it works anymore. That file basically registers a custom handler that will do certain things otherwise defers the default Houdini handler. I believe that due to the way the default Houdini handler stuff was implemented it was pretty much impossible to just call their code while adding in your own hooks so it required making a copy of a bunch of the Houdini code to handle the actual pasting the way they do (nodegraph.handle_houdini_paste_event) and then eventually doing something that you want to do, which in this case was me emitting a callback for my own crappy callback system.

I recall it was a bit of a pain to figure out and a lot of diving into various places but we eventually figured out something that worked well enough for our goals.

Thanks for the great info, although the news is a bit sad! haha.
User Avatar
Member
155 posts
Joined:
Offline
If you specifically want an action done when pasting, can't you use the "OnLoaded" event type?

https://www.sidefx.com/docs/houdini/hom/locations.html#event-types [www.sidefx.com]

If you put it in "$HOUDINI_PATH/scripts/OnLoaded.py" it should run any time a node is loaded or pasted.

-Jon
User Avatar
Member
185 posts
Joined: March 2011
Online
jparker
If you specifically want an action done when pasting, can't you use the "OnLoaded" event type?

https://www.sidefx.com/docs/houdini/hom/locations.html#event-types [www.sidefx.com]

If you put it in "$HOUDINI_PATH/scripts/OnLoaded.py" it should run any time a node is loaded or pasted.

-Jon

Have you tried that? Because in my tests this action was not triggered when (alt + drag) copying.
User Avatar
Member
155 posts
Joined:
Offline
I've just implemented it for a project I'm working on. I tried both pasting and alt-dragging and my callbacks still work. This is Houdini 19.5 in Linux.

The code in that file is pretty simple:

import my_callback
import my_object

if hou.isUIAvailable():
    my_callback(kwargs['node'], my_object)
User Avatar
Member
185 posts
Joined: March 2011
Online
jparker
I've just implemented it for a project I'm working on. I tried both pasting and alt-dragging and my callbacks still work. This is Houdini 19.5 in Linux.

The code in that file is pretty simple:

import my_callback
import my_object

if hou.isUIAvailable():
    my_callback(kwargs['node'], my_object)

Thanks for letting me know. I'll give it another try.
User Avatar
Member
1814 posts
Joined: Nov. 2006
Online
Personally I would not use OnLoaded.py for this as there is no way to actually differentiate whether it's being called as part of a hip file load or by pasting a node.

Trying to use hou.isUIAvailable() to guard against this won't really do much other than prevent your callback from running if you load a hip file in hython; it will always return True in this context if you're running an interactive session, regardless of if you load a hip file via command line or File > Open.

Given that OnLoaded is also run against every node in a file it can also have the unintended consequence of dramatically slowing down startup/file loading if the hip file contains a huge amount of nodes.
Edited by graham - Jan. 20, 2023 15:21:08
Graham Thompson, Pipeline Things
  • Quick Links