BVtkNodes
BVtkNodes copied to clipboard
Importing nodes in a script
When I try to import nodes within my script, like,
ops.node.bvtk_node_tree_import(filepath='example.json')
I get a Runtime Error:
RuntimeError: Operator bpy.ops.node.select_all.poll() failed, context is incorrect
.
I tried changing to EDIT
mode from OBJECT
mode and I still get the same error.
How can I properly import nodes in my script?
Hi @vigeesh ,
There seems to be wrong context for bpy.ops.node.select_all
. Can you share more of your code?
Hi @tkeskita,
Basically, I am just importing bpy
and then calling the node_tree_import
function, like this,
import bpy
bpy.ops.node.bvtk_node_tree_import(filepath='example.json')
I also tried to create a node tree before calling the function, like,
import bpy
bvtkn = bpy.data.node_groups.new('NodeTree',type='BVTK_NodeTreeType')
bpy.ops.node.bvtk_node_tree_import(filepath='example.json')
But, they both give the same context is incorrect
error.
Here's the traceback,
Error: Traceback (most recent call last):
File "/home/vigeesh/.config/blender/2.80/scripts/addons/BVtkNodes-master/tree.py", line 309, in execute
bpy.ops.node.select_all(action='SELECT')
File "/home/vigeesh/blender/2.80/scripts/modules/bpy/ops.py", line 201, in __call__
ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.node.select_all.poll() failed, context is incorrect
location: /home/vigeesh/blender/2.80/scripts/modules/bpy/ops.py:201
Hello @vigeesh ,
due to bpy.ops.node.bvtk_node_tree_import
using bpy.ops.node.select_all
, it is only possible to run it from node tree context (e.g. operator in node editor). If I got this right, it is currently not possible to use it from a script that is run from Text Editor, sorry.
For more information about operators in python, see Gotcha's in Blender Python manual