1

I am trying to invoke a custom operator from a blender addon, e.g. this one. However, when I call it from the command line I am getting the following error message:

>>> bpy.ops.node.liexport('INVOKE_DEFAULT')
Error: Traceback (most recent call last):
  File "/ttsesm/blender/blender-2.83.2-linux64/2.83/scripts/addons/vi-suite06/vi_operators.py", line 607, in invoke
    node = context.node
AttributeError: 'Context' object has no attribute 'node'

location: /ttsesm/blender/blender-2.83.2-linux64/2.83/scripts/modules/bpy/ops.py:199

Traceback (most recent call last): File "<blender_console>", line 1, in <module> File "/ttsesm/blender/blender-2.83.2-linux64/2.83/scripts/modules/bpy/ops.py", line 199, in call ret = op_call(self.idname_py(), C_dict, kw, C_exec, C_undo) RuntimeError: Error: Traceback (most recent call last): File "/ttsesm/blender/blender-2.83.2-linux64/2.83/scripts/addons/vi-suite06/vi_operators.py", line 607, in invoke node = context.node AttributeError: 'Context' object has no attribute 'node'

from my understanding the explanation is related to what @batFINGER is describing here. But then my question would be how to invoke the operator from the script.

The operator is related with the Export button that you can see in the node below:

enter image description here

and which node I created with the following commands:

ng = bpy.data.node_groups.new('NodeTree', 'ViN')
context_node = ng.nodes.new(type="No_Li_Con")
ttsesm
  • 409
  • 3
  • 10

1 Answers1

2

The solution I've found was to to override the context.node call. The way I did it was by creating a dictionary with 'node' as the key and the node as the item, e.g.

override = {'node': bpy.data.node_groups[node_group_name].nodes['node_name']}

The operator can then be run with bpy.ops.node.ligexport(override, 'INVOKE_DEFAULT']).

ttsesm
  • 409
  • 3
  • 10
  • That'll do it. The node editor has an active_node and node (IIRC) context member. Use layout.context_pointer_set("node", node) to set it in the layout if not using from node editor. – batFINGER Oct 15 '20 at 16:45
  • How is the layout.context_pointer_set() is defined? Because I am getting NameError: name 'layout' is not defined. – ttsesm Oct 16 '20 at 13:13
  • In draw code layout = self.layout If it is used before an operator layout.operator(...) the operator will have that context member. eg may be in the 3d view or properties UI. – batFINGER Oct 16 '20 at 13:18
  • Apologies, I do not understand what do you mean and how to use it :-( – ttsesm Oct 16 '20 at 13:35