Pynodes problems

I have coded 3 pynodes:
A, B - input nodes (with output image socket)
C - output node (that will receive image from input socket)
Image is stored in global cache dictionary - something like that:
-nodes_tree_cache[hash(node_x_id+node_x_socket_id)]= numpy.array(from image pixels).

I have problems detecting node tree changes like link was created/modified/removed by user. I mean the problem is that there are to many updates happening from bpy.types.Node.update() function for example:

  • deleting node A - fires update in both nodes B,C and every other node - even in they were unconnected to A.
  • same goes for adding link, removing link, duplicating link - update() if executed on all nodes even if they are unconnected at all.

I can use bpy.types.Node.insert_link() - works ok for updating node linked.to_node but it won’t give me ability to detect link deletion.

Basically there is no easy way to detect:

  • link x was deleted so execute update in link.to_node,
  • link x was added so update link.to_node,
  • link x was modified - changed sockets,

I wish that maybe bpy.types.NodeTree.update() - could give me arguments with modified links, and from them I could detect affected nodes (link.to_node) that need update.
Or maybe I’m doing stuff wrong andn there is a way to make node updates work. For now I store list of nodeTree links ids, and in each NodeTree.update() I search for removed, added links.

1 Like