BVtkNodes icon indicating copy to clipboard operation
BVtkNodes copied to clipboard

Importing nodes in a script

Open vigeesh opened this issue 5 years ago • 3 comments

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?

vigeesh avatar Dec 04 '19 10:12 vigeesh

Hi @vigeesh ,

There seems to be wrong context for bpy.ops.node.select_all. Can you share more of your code?

tkeskita avatar Dec 07 '19 11:12 tkeskita

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

vigeesh avatar Dec 09 '19 09:12 vigeesh

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

tkeskita avatar Dec 09 '19 16:12 tkeskita