0

I'am trying to use the Python API to make a lot of different and randomized trees with the MTree add-on. But I'am struggling with an error telling me that the context is incorrect.

RuntimeError: Operator bpy.ops.node.add_node.poll() failed, context is incorrect

I've tried to use the bpy.context.active_node but that doesn't seem to exist even though it's in the documentation.

For now my code looks like this:

import bpy
bpy.ops.node.new_node_tree(type="mtree_node_tree", name="Tree1")
bpy.context.area.add_node(type="MtreeParameters", use_transform=True)

But it gives out an error which I listed before at the 3rd line. The code should just put a node into the node tree, but it probably doesn't know where to.

So does anyone know how to make the node tree the context?

  • Is a member of the context of the node editor space. This is why it is listed under Node Context – batFINGER Mar 20 '21 at 08:45
  • Example here https://blender.stackexchange.com/questions/6101/poll-failed-context-incorrect-example-bpy-ops-view3d-background-image-add Closed _In as much as this is re node context, it is the same issue, focused on area type 'NODE_EDITOR' _ – batFINGER Mar 20 '21 at 08:53

0 Answers0