B3.2 Additionnal handler at each node change?

Hi all :slight_smile:

I’d like to know wether it is possible to add a handler a every node editor change ?
Something tied to the ‘undo’ handler for example…

I’d like to make a procedural texture editor and this is why i need this.

Anyone for help ? :slight_smile:

Thanks and happy blending !

Pretty sure depsgraph_update covers the node graph, that should do it

Hi @joseph

Indeed it does :smiley:

But the handler is always called. even when i move an object in 3D view.
What i want is the handler to be called ONLY when nodes window changes

You got any idea ? :slight_smile:

Hmm… you could save a temporary list of all the nodes in the graph; should be a simple “for z in y” deal, and compare that with the current nodes on depsgraph_update. If they’re different, do something, otherwise, do nothing

This is an idea…
Or maybe just memo the nodes count :slight_smile:

This should be cheaper from a CPU point of view.

But… :stuck_out_tongue:

I need the handler to be called when user changes for example a value in nodes editor…

Isn’t there a way in blender to detect the window or the area the mouse pointer is over ?
There is indeed, as it is used when you open/close an N panel… but is it ‘catchable’ ?

You can filter ID types that were tagged during a depsgraph update.

See id_type_updated for a list of possible ID type string enums.

import bpy

def on_nodetree_change(scene, depsgraph):
    if depsgraph.id_type_updated("NODETREE"):
        print("Node tree updated")


bpy.app.handlers.depsgraph_update_post.append(on_nodetree_change)

Calling id_type_updated is cheap. It just tests a byte array against zero.
In the above example _post is used. You can also use the _pre handler, but note that the depsgraph argument in the _pre handler will be None when the callback is called.

wow !!! :open_mouth:

I go give this a try right away @iceythe

And be back here quickly !

Thanks a lot and happy blending ! :smiley:

You are as usual, my semi-god saviour @iceythe :smiley:

This is precisely what i needed !!!

I had no idea of how to dig in depsgraph data and get what i needed in it. The strange thing is that the handler i used ( took from an example on the web ) did not have the depsgraph parameter. I only had the scene one and didn’t know how to deal with it.

My obvious lack of blender internals often blocks me and most of the time the blender API online doc is of no help to me. Is there somewhere on the web a ‘from surface-to-depth’ documentation on what blender API offers with generic but complete examples ( just like the unity3D online doc ) ?

Thanks you very very much ! And have a great day !

Happy blending ! :slight_smile: