Any ideas why the subscription via msgbus to property changes (node/attr) are dropped while starting a new blend or reloading a blend file?
I use msgbus to subscribe to changes to a node name (in the sverchok blender add-on) and I setup these subscriptions once in the register() of one of my nodes that need to monitor such changes. Everything works fine after I just launch Blender.. however, once I reload a saved blender file or create new blend the subscription does not work anymore. Reloading the scripts fixes the problem (since the subscription call is re-run).
(see here a video version of this description: https://youtu.be/-KwFKuxbnJs)
VIZ_NODE1 = sverchok.nodes.viz.vd_draw_experimental.SvVDExperimental
VIZ_NODE2 = sverchok.nodes.viz.viewer_idx28.SvIDXViewer28
subscribe_to_list = [(VIZ_NODE1, "name"), (VIZ_NODE2, "name")]
def msgbus_callback(*args):
message = args[0]
print("msgbus_callback: ", message)
# propagate the messsasge to all layer nodes
layer_nodes = [n for n in bpy.data.node_groups['NodeTree'].nodes if n.bl_idname == "SvViewerLayerNode"]
for node in layer_nodes:
print("propagate msgbus callback to:", node.bl_idname)
node.viewer_changed_name()
owner = object()
def subscribe_to_viewer_changes(subscribe_to):
# listen for changes to the "name" property of any node of viewer classes
print("layer_nodes_subscribe_to_viewer_changes: ", subscribe_to)
bpy.msgbus.subscribe_rna(
key=subscribe_to,
owner=owner,
args=("Viewer node name property has changed",),
notify=msgbus_callback,
)
def layer_nodes_subscribe_to_viewer_nodes_name_changes():
print("layer_nodes_subscribe_to_viewer_changes")
for subscribe_to in subscribe_to_list:
subscribe_to_viewer_changes(subscribe_to)
...
def register():
print("Registering the SvViewerLayerNode classes")
_ = [bpy.utils.register_class(cls) for cls in classes]
layer_nodes_subscribe_to_viewer_nodes_name_changes()
```