-3
$\begingroup$

How can I properly set up context in plugins?

I am importing Digital Terrain Models using a python plugin.

def register():
    bpy.utils.register_class(DTM)
    bpy.types.INFO_MT_mesh_add.append(add_to_menu)

I get the following error.

C_dict, C_exec, C_undo = BPyOpsSubModOp._parse_args(args) File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\modules\bpy\ops.py", line 142, in _parse_args raise ValueError("1-3 args execution context is supported") ValueError: 1-3 args execution context is supported

How can I fix this?

$\endgroup$
8
  • 1
    $\begingroup$ Which addon is that? If it isn't the "HiRISE DTM" one, please give a link to the full source code. $\endgroup$
    – Adhi
    Commented Jun 11, 2013 at 2:43
  • 1
    $\begingroup$ This looks more like a bug report then a question. $\endgroup$
    – ideasman42
    Commented Jun 11, 2013 at 2:59
  • $\begingroup$ Maybe it's something in add_to_menu, trying to call an operator with incorrect arguments. $\endgroup$
    – Adhi
    Commented Jun 11, 2013 at 3:16
  • $\begingroup$ try:<br/> dtm = bpy.ops.import_img.load(self,context,filepath=self.filepath,scale=self.scale,bin_mode=self.bin_mode, cropVars=False,)<br/> except ValueError:<br/> print("location: <unknown location> -1")<br/> $\endgroup$
    – ogeid
    Commented Jun 11, 2013 at 3:16
  • $\begingroup$ You don't need self and context when calling an operator. Those first two argument positions are reserved for execution context. $\endgroup$
    – Adhi
    Commented Jun 11, 2013 at 3:18

1 Answer 1

6
$\begingroup$

When calling an operator with self and context, I get the exact same error message:

ValueError: 1-3 args execution context is supported

The first 3 arguments are reserved for optional arguments. From Blender API documentation on running an operator:

For calling operators keywords are used for operator properties and positional arguments are used to define how the operator is called.

There are 3 optional positional arguments (documented in detail below).

bpy.ops.test.operator(override_context, execution_context, undo)
  • override_context
  • dict type execution_context - string (enum)
  • undo - boolean

Each of these arguments is optional, but must be given in the order above.

In short, calling an operator with self and context as the first two arguments is wrong, and maybe the cause of the error message you've shown.

$\endgroup$
4
  • $\begingroup$ you're right. so using bpy.ops.import_img.load(self, with proper context would return MESH in the best of cases $\endgroup$
    – ogeid
    Commented Jun 11, 2013 at 3:39
  • $\begingroup$ I got this error when I had the syntax: bpy.ops.object.join(obj2) and resolved it by removing obj2, so just: bpy.ops.object.join() I thought the second object to be joined to the first but it turns out the join operator uses selected objects and an active object... it does not expect objects to be passed as arguments. Makes sense once you know. (Just posting this example in case it helps someone with a similar problem.) $\endgroup$
    – Mentalist
    Commented Nov 2, 2020 at 7:25
  • $\begingroup$ However... the join operator can accept a copy of the scene context! ctx = bpy.context.copy() then join(ctx) assuming the selected objects and active object in the context are valid. I don't know the details of why this works, but here's the answer that demonstrates it. The manual currently doesn't explicitly mention any ability of join() to accept arguments though. $\endgroup$
    – Mentalist
    Commented Nov 2, 2020 at 8:24
  • $\begingroup$ I found that the functions require the argument in a variable=value syntax like: bpy.ops.mesh.decimate(ratio=0.18) if I try bpy.ops.mesh.decimate(0.18) I get that 1-3 params error too, I dont know if this is like that only on newer blender versions, mine is 2.93.4 $\endgroup$ Commented Dec 3, 2021 at 3:30

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