Event Callback on DisplayFlag checked: It runs twice. Why?

   2702   3   2
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
My digital asset can have multiple instances at the same time in the Network View pane.
Whenever the user checks the display flag on one of those instances, I want to print the name of the instance with the display flag just checked.

To implement this, I've inserted a python sop just before the output of the digital asset, with the following code:
node = hou.pwd()
geo = node.geometry()
OTLinstance = node.parent()

def flag_changed(node, event_type, **kwargs):
    if OTLinstance.isGenericFlagSet(hou.nodeFlag.Display) == 1:
        print(OTLinstance.name(), " has the Display Flag on")
    
OTLinstance.addEventCallback((hou.nodeEventType.FlagChanged,), flag_changed)

It kind of works, but every time the Display Flag changes, the Python Sop returns TWICE the text.
So I guess it's making unnecessary cycles.
1) Why does this happen?
2) Do you know a better method to implement this behavior in a Digital Asset?

Thanks for any help!
I've attached a file example with the above code
Edited by Andr - March 7, 2019 12:50:45

Attachments:
Q_check_DisplayFlag.hiplc (64.0 KB)

User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
I tried another road: register the event callback inside the OnLoaded event handler script of the Digital Asset.
But I get the same issue: the callback function is being run twice.


The code I'm using in the OnLoaded event handler script is:
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)



Please refer to the attached file that has an embedded digital asset example
Edited by Andr - March 8, 2019 07:57:34

Attachments:
Q_onLoaded_checkFlag.hiplc (43.8 KB)

User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
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.
User Avatar
Member
78 posts
Joined: May 2018
Offline
Going to resurrect this thread and say that this callback really needs to pass along some info about what flag was toggled. Otherwise I have to track that info myself.
  • Quick Links