Jump to content
gemini

Event firing when a node is Deleted ( not HDA )

Recommended Posts

Hi,

Can houdini pythyon can solve this: I have an object (rop network in obj) when is deleted I want to run a py script. 

Thanks in advance !

Sz

Share this post


Link to post
Share on other sites

You can right click on the rop network, go on type properties -> scripts and on Event Handler (at the bottom) you can put "on deleted" in the dropdown menu. Then on the right panel, in Edit as, you can change from Hscript to Python and write your script.

When you delete the node, this script will be executed. 

Share this post


Link to post
Share on other sites

Thanks, but I don't think it's a good sollution to override the factory default otls definition.  It causes a lot of error.

Maybe has other way. Any Idea ?

Sz

Share this post


Link to post
Share on other sites

You are right gemini, that's not a good idea.

 

This is interesting. The documentation says that if is used "addEventCallback(event_types, callback) "  is valid just on the current instance and session of Houdini. What if I want to make it valid for this particular instance but also for every time I open Houdini again?

 

Share this post


Link to post
Share on other sites

Thanks, when the hip is opened a script should init the node events..

 

But I can't get it work now.  My simple example:

n = hou.node('/obj/null1')

n.addEventCallback( hou.nodeEventType.BeingDeleted , hou.session.a())

 

It writes:

TypeError: in method 'Node_addEventCallback', argument 2 of type 'std::vector<HOM_En
umValue *,std::allocator<HOM_EnumValue * > > const &'

 

Any Idea ?

 

 

Share this post


Link to post
Share on other sites

The problem is that it expects the first arg to be an iterable of enums, not just a single:

n.addEventCallback( [hou.nodeEventType.BeingDeleted] , hou.session.a())

 

Share this post


Link to post
Share on other sites

Thanks, I get closer..

I check: Delete the Node.

I have a strange error.. While run event callback:

TypeError: 'NoneType' object is not callable

 

My Session code:

def a():
    print 1
    

DOes it causes the deleted node ? Any Idea? THX

Share this post


Link to post
Share on other sites

You don't need to call your function inside your event callback

n.addEventCallback( [hou.nodeEventType.BeingDeleted] , hou.session.a)

Also you might need to add **kwargs arguments to your function depending on the event type as specified in the documentation.

Please refer the example given here: http://www.sidefx.com/docs/houdini/hom/hou/Node.html#addEventCallback

Hope it helps :)

Cheers

-J

Share this post


Link to post
Share on other sites
Posted (edited)
On 10/11/2018 at 5:57 PM, Andrea said:

This is interesting. The documentation says that if is used "addEventCallback(event_types, callback) "  is valid just on the current instance and session of Houdini. What if I want to make it valid for this particular instance but also for every time I open Houdini again?

 

I would like to know as well. It seems that for a Digital Asset instance you should register the event callback inside the OnLoaded event handler script. Am I right?

Indeed, I'm currently registering an event callback (flag change) for a Digital Asset inside an onLoaded script.

My issue is that the callback function is being run twice. Do you happen to know the reason?
This is the code I'm using inside the onLoaded script:

node = hou.node("/obj/geo1/flagchanged1")
def flagChanged(event_type, **kwargs):
    if node.isGenericFlagSet(hou.nodeFlag.Display) == 1:
        print("display flag is set")


node.addEventCallback((hou.nodeEventType.FlagChanged,), flagChanged)

---------------------------------

---------------------------------

UPDATE. For anybody that might face the same issue in the future:

I believe I understand what's going on: it runs two times because when you change the Display Flag on a node with the left mouse button you would automatically set the render flag as well. So you are actually setting two flags with one click, that's why the event .FlagChanged is being triggered 2 times.

Indeed, If you try to use the combination alt+LMB to exclusively set the display flag (and leave the render flag in place), the event callback is triggered only 1 time.

I guess that you can't really avoid this behavior and, in order to trigger 1 single event callback when the display flag is changed, you should write some conditional and use some toggle parameter to write to and check against it every time the event callback is triggered.

-------------------------------

 

 

Q_onLoaded_checkFlag.hiplc

Edited by Andr1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×