Skip to content

Commit

Permalink
Fixing "Run Script" support for Blender 4.0 JacquesLucke#153
Browse files Browse the repository at this point in the history
Issue summary:
When using the "Run Script" command, the user hits
`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`

Issue cause:
This issue is connected to a breaking change that was introduced in Blender's 4.0 Python API update

https://wiki.blender.org/wiki/Reference/Release_Notes/4.0/Python_API
> Blender Operators (bpy.ops)
> Remove the context override argument to bpy.ops in favor of context.temp_override(..) ([ac263a9bce](https://projects.blender.org/blender/blender/commit/ac263a9bce53e190d07d679a058a230e91e722be))

For Blender 4.0 in `.\pythonFiles\include\blender_vscode\operators\script_runner.py` instead of this
`bpy.ops.dev.run_script(context, filepath=path)`

We need to use this
```
    with bpy.context.temp_override(**context):
        bpy.ops.dev.run_script(filepath=path)
```

Tested "Run Script" and Add-on Debugging under Blender 2.9 and Blender 4.0
  • Loading branch information
CGArtPython committed Nov 20, 2023
1 parent 312671b commit 55fe6bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Fixed
- Fixed "Run Script" support for Blender 4.0.

## [0.0.18] - 2023-04-02


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ def execute(self, context):
def run_script_action(data):
path = data["path"]
context = prepare_script_context(path)
bpy.ops.dev.run_script(context, filepath=path)

if bpy.app.version < (4, 0, 0):
bpy.ops.dev.run_script(context, filepath=path)
return

with bpy.context.temp_override(**context):
bpy.ops.dev.run_script(filepath=path)


def prepare_script_context(filepath):
with open(filepath) as fs:
Expand Down

0 comments on commit 55fe6bb

Please sign in to comment.