1
$\begingroup$

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")
$\endgroup$

1 Answer 1

2
$\begingroup$

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']).

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$
    – batFINGER
    Oct 15, 2020 at 16:45
  • $\begingroup$ How is the layout.context_pointer_set() is defined? Because I am getting NameError: name 'layout' is not defined. $\endgroup$
    – ttsesm
    Oct 16, 2020 at 13:13
  • $\begingroup$ 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. $\endgroup$
    – batFINGER
    Oct 16, 2020 at 13:18
  • $\begingroup$ Apologies, I do not understand what do you mean and how to use it :-( $\endgroup$
    – ttsesm
    Oct 16, 2020 at 13:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .