I'd like to access the active custom custom node tree in the Python code. It can be done through

    bpy.data.node_groups["name of the custom node tree"]

However there could be many node trees of the same type, so the name of the currently open node tree is unknown.


Although there could be any type of nodetrees in bpy.data.node_groups, their names are unique and used as Identifiers.

So bpy.data.node_groups['Name of the Nodetree'] means exactly the nodetree with that name, no matter what type it has.

About the active node_tree you need to use the Node Editor's context, either by checking if the active node or the active node_tree is a node_group.

For example, if you have a custom node in a node_tree, and you want to access the node_tree itself from that node, you can look in the context:

node_tree = bpy.context.space_data.edit_tree

This will return the current tree being edited in the editor.

  • 1
    $\begingroup$ So can you provide a code snippet to get access to the active node tree? $\endgroup$ – vvoovv Apr 26 '19 at 6:11
  • $\begingroup$ it depends from where you are (editor), and which nodetree you want to access (material/world/compositor/nodegroup/etc). There are plenty of possibilities, so you need to describe exactly what's your user case. $\endgroup$ – Secrop Apr 26 '19 at 11:26
  • $\begingroup$ I have a number of custom node trees of the same type in Blender 2.80. They can be found in bpy.data.node_groups. Is more information required? $\endgroup$ – vvoovv Apr 26 '19 at 11:38
  • 1
    $\begingroup$ I'd like to access the node tree in the method insert_link(..) of a custom node. $\endgroup$ – vvoovv Apr 26 '19 at 11:42
  • 1
    $\begingroup$ I've updated the answer! ;) $\endgroup$ – Secrop Apr 26 '19 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.