Hi, I'm wrestling with getting an efficient event system based on the playbar. I think it's great that I don't need to make a node time-dependent in order to get events from the starting and stopping of the playbar, awesome!
However, this is pretty limiting if I can't pass it data. Here's my incredibly hacky attempt to do that. I basically want to give this function data from a node that could change it's input or properties. If I can't do that, then I can feed it a string to the node itself and go from there. But, anyone looking at my image should be horrified with the hackiness of the hack.
Any suggestions?
What is best way to send data to a playbar event callback?
1702 4 1- andrewlowell
- Member
- 539 posts
- Joined: 12月 2005
- Offline
- andrewlowell
- Member
- 539 posts
- Joined: 12月 2005
- Offline
I've got a working solution. It's not exactly what I had in mind but I'm wondering if anyone thinks this is workable.
In my node/hda .. I've got a python sop that now appends the node itself to the hou.session module, as a variable.
From there I'm able to read whatever data I'd like off of the node by accessing that variable in the play function.
For instance:
then in the playbar function ...
I'm still curious if there is a way to send this callback data directly.
In my node/hda .. I've got a python sop that now appends the node itself to the hou.session module, as a variable.
From there I'm able to read whatever data I'd like off of the node by accessing that variable in the play function.
For instance:
hou.appendSessionModuleSource('player_node = hou.node("' + hda.path() + '")')
then in the playbar function ...
frame_to_do_something_on = hou.session.player_node.evalParm('frame_to_do_something_on')
I'm still curious if there is a way to send this callback data directly.
Edited by andrewlowell - 2023年1月1日 21:45:57
- tamte
- Member
- 8833 posts
- Joined: 7月 2007
- Offline
I don't know the exact use case you are after
I'd personally avoid Python SOP as there is no need to keep adding the callback, just add it during OnCreate or something
you can do something like this in OnCreated callback
I'd personally avoid Python SOP as there is no need to keep adding the callback, just add it during OnCreate or something
you can do something like this in OnCreated callback
current_node = kwargs['node'] def myPlaybarEvent(event_type, frame): print ("Playbar event", event_type, "at frame", frame) node = current_node print(node.path()) hou.playbar.clearEventCallbacks() hou.playbar.addEventCallback(myPlaybarEvent)
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
- andrewlowell
- Member
- 539 posts
- Joined: 12月 2005
- Offline
Thanks for weighing in. It's probably best to initialize the callbacks on created yes. But the time it takes to update this is nil so I'm ok with that.
The issue is that current_node won't be available once the callback is playing. So my current solution is to save the current_node to a hou.session variable, such as hou.session.current_node
The issue is that current_node won't be available once the callback is playing. So my current solution is to save the current_node to a hou.session variable, such as hou.session.current_node
- tamte
- Member
- 8833 posts
- Joined: 7月 2007
- Offline
andrewlowellseems to work for me as written
The issue is that current_node won't be available once the callback is playing
my reasoning is that the
kwargs['node']
gets evaluated into node reference during OnCreatedthen the defined function just hardcodes that reference in the definition
so that when the event calls it, it will use that hardcoded node reference in event registered during on created so should work as long as the node exists if deleted it will start erroring out, but that can be taken care of in OnDeleted
Edited by tamte - 2023年1月1日 23:59:22
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
-
- Quick Links