1
$\begingroup$

Related to the question here I wanted now to use the export custom node from the same addon. Considering that the invoke() function calls the file browser for setting the path the filename I would like to call the execution() function directly but by overriding the self.filepath variable. I've tried to follow the same trick as in the linked question, meaning:

override = {'node': bpy.data.node_groups['<node_group_name>'].nodes['VI CSV Export'], 'self.filepath':'<path_to_save_file>.csv'}
bpy.ops.node.csvexport(override, 'EXEC_DEFAULT')

But this complaints with the following error:

Error: Traceback (most recent call last):
  File "/ttsesm/blender-2.83.6-linux64/2.83/scripts/addons/vi-suite06/vi_operators.py", line 2200, in execute
    node = self.node
  File "/ttsesm/blender-2.83.6-linux64/2.83/scripts/modules/bpy_types.py", line 713, in __getattribute__
    return super().__getattribute__(attr)
AttributeError: 'NODE_OT_CSV' object has no attribute 'node'

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


Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "/ttsesm/blender-2.83.6-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-2.83.6-linux64/2.83/scripts/addons/vi-suite06/vi_operators.py", line 2200, in execute
    node = self.node
  File "/ttsesm/blender-2.83.6-linux64/2.83/scripts/modules/bpy_types.py", line 713, in __getattribute__
    return super().__getattribute__(attr)
AttributeError: 'NODE_OT_CSV' object has no attribute 'node'

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

My questions are why the node = self.node cannot be overridden and whether the way that I am overriding the self.filepath variable is the correct one.

$\endgroup$
6
  • $\begingroup$ It's not a trick, you override context. ie you are overriding the operator what value context.node has. Not operator properties. Most likely want to use bpy.ops.foo.bar(override, filepath="...") $\endgroup$
    – batFINGER
    Oct 16, 2020 at 16:17
  • $\begingroup$ Why the node = self.node was not overridden by the {'node': bpy.data.node_groups['<node_group_name>'].nodes['VI CSV Export']} though? Like in the other case. I guess because it is not a context anymore, but then how I override it in this use case if possible. $\endgroup$
    – ttsesm
    Oct 16, 2020 at 16:33
  • $\begingroup$ if self.node = context.node is set in the invoke method of the operator also put in 'INVOKE_DEFAULT' as second argument like the other time. The operator is designed to be invoked by pressing its button in the UI of the node. (in this case you cannot bypass the invoke method by the looks) $\endgroup$
    – batFINGER
    Oct 16, 2020 at 16:38
  • $\begingroup$ but 'INVOKE_DEFAULT' will activate the context.window_manager.fileselect_add(self) which I do not want, since I want to bypass this part. $\endgroup$
    – ttsesm
    Oct 16, 2020 at 16:41
  • $\begingroup$ As I suspected it is set in the invoke method See github.com/rgsouthall/vi-suite06/blob/… Does it still throw the filebrowser if the filepath is set? Or edit addon to use context.node instead. Not sure of the point of setting it as an operator property. $\endgroup$
    – batFINGER
    Oct 16, 2020 at 16:48

1 Answer 1

0
$\begingroup$

self.node is set in invoke.

THe operator is designed to be invoked by pressing its button displayed on its node.

The operator defines

self.node = context.node

in its invoke method, and uses self.node in its execute method, and will hence not work unless invoked.

bpy.ops.foo.bar(override, 'INVOKE_DEFAULT', filepath=somefilepath)

IMO the simple fix is to edit the operator to use context.node as the node in place of self.node by placing

self.node = context.node

in the execute method also.

Alternatively return self.execute(context) from the invoke method if the value passed to self.filepath is a valid filepath and use

bpy.ops.foo.bar(override, 'INVOKE_DEFAULT', filepath=somefilepath)

to ensure it is invoked and node is set.

A note on overriding.

What you are passing in the override dictionary are context members, eg

override = {"foo" : "bar"}

then if passed as an override to the operator

context.foo == "bar"

is true within the operator.

The filepath is a property of the operator, not the context and is hence not going to do diddly squat if passed as part of the override. The operator (self) and context are not the same. Pass it to the operator as a keyword variable.

Fork it.

Finally, fork and make the changes, or suggest / request changes to the maintainer of the addon, so that it can be executed directly, or to find out if there are reasons why it cannot.

$\endgroup$
1
  • $\begingroup$ Thanks for the feedback @batFINGER. I try to ask the author to change the node = self.node to self.node = context.node if there is not any problem. Alternatively I can create and call my own method based on his execute() one for saving the file. $\endgroup$
    – ttsesm
    Oct 19, 2020 at 8:02

You must log in to answer this question.

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