Query from what node an operation is executed

Hi guys,
could maybe someone help me out by pointing me the right way with this. I am having a custom node onto which I want to add a button (to create a material in this case). I have multiple of those nodes in my tree, but I can’t seem to figure out, how I can let the operator know, from which of those nodes it has been executed.
Thanks a lot in advance for any clues,
Stefan

You could try creating a custom StringProperty in your operator that you pass the name of the node to in the node draw function, kinda like this:

class MYOP_OT_my_operator(Operator):
    bl_idname = "test.my_op"
    node_name: StringProperty()

    def execute(self, context):
        node = node_tree.nodes[self.node_name]

Then in the draw function for the node do:

op = layout.operator("test.my_op")
op.node_name = self.name

Hope that helps!

Ah thank you very much, that looks actually like a straight forward approach. Gonna try it right out

1 Like

yessss, thank you so much Strike_Digital, got it working

1 Like