# PyNodes: get active node tree from context in Blender 2.72

I'm working on a custom nodetree-based addon for scientific analysis. My code requires knowledge of the active nodetree in the current context (or alternatively the parent nodetree of a selected node) which I haven't been able to obtain yet.

I noticed the addition of a "get_from_context" NodeTree class method in the 2.72 API changelog (http://www.blender.org/documentation/blender_python_api_2_72_release/bpy.types.NodeTree.html#bpy.types.NodeTree.get_from_context) which would be perfect. However when I try to call it from either bpy.types.NodeTree or an existing NodeTree object I get an attribute not found error.

What is the correct way to call this method from the NodeTree class directly? Or does anyone else have this issue? I'm quite new to Blender python dev so it could be a stupid mistake.

Alternatively, does anyone know of a way to obtain a node's parent nodetree?

To get the parent of any node:

node.parent


To get the node, you can get it from the context active_node, if you can access the Nodes context, or, from the global context, get the scene and then the node from the correct node tree.

The function get_from_context you mention is a part of the NodeTree class. You would have to show your code for me to know what is the problem.

• neither the parent field nor the get_from_context method works for me.
– IARI
Jul 25 '18 at 8:29
• @IARI what is the problem you are encountering and the blender version? Jul 27 '18 at 19:07
• Blender 2.79, and the problem as descriped is, that the 'get_from_context' which is documented as Classmethod of the NodeTree class seems to not exist. I was trying to create an operator for a button in nodes to remove sockets. The operator needs to know the node socket - so right now im saving as a stringproperty inside the operator the names of all: nodetree, node, and identifier of the nodesocket - I had hoped that this can be avoided by the use of existing methods such as get_from_context.
– IARI
Jul 30 '18 at 10:45