0

I have this code in my addon. It just runs view_all() operator from another context.

        for area in context.screen.areas:
            if area.type == 'DOPESHEET_EDITOR':
                for region in area.regions:
                    if region.type == 'WINDOW':
                        ctx = context.copy()
                        ctx['area'] = area
                        ctx['region'] = region
                        bpy.ops.action.view_all(ctx)
                        break
                break

It works perfectly fine in 3.3 or 3.6 but with 4.0 it gives me the error below:

line 76, in execute
    bpy.ops.action.view_all(ctx)
  File "C:\Program Files\Blender Foundation\Blender 4.0\4.0\scripts\modules\bpy\ops.py", line 106, in __call__
    C_exec, C_undo = _BPyOpsSubModOp._parse_args(args)
  File "C:\Program Files\Blender Foundation\Blender 4.0\4.0\scripts\modules\bpy\ops.py", line 60, in _parse_args
    raise ValueError("1-2 args execution context is supported")
ValueError: 1-2 args execution context is supported

I couldn't find any braking change in the API that would cause this and I have no idea why it's not working.

Fatih
  • 3
  • 1

1 Answers1

1

Blender dev team added a new API for overriding context some time ago:

https://docs.blender.org/api/current/bpy.ops.html#overriding-context

Overriding context should be implemented this way, context attribute was deprecated and disabled in 4.0. Info in release notes:

Blender Operators (bpy.ops)
Remove the context override argument to bpy.ops in favor of context.temp_override(..) (ac263a9bce)

So your script should be changed this way:

import bpy
from bpy import context
for area in context.screen.areas:
        if area.type == 'DOPESHEET_EDITOR':
            for region in area.regions:
                if region.type == 'WINDOW':
                    ctx = context.copy()
                    ctx['area'] = area
                    ctx['region'] = region
                    with context.temp_override(**ctx):
                        bpy.ops.action.view_all()
                break
        break

Crantisz
  • 35,244
  • 2
  • 37
  • 89