From 55fe6bb89bcdf14bedf25b89f2176848c386e534 Mon Sep 17 00:00:00 2001 From: CGArtPython Date: Mon, 20 Nov 2023 01:05:26 -0800 Subject: [PATCH] Fixing "Run Script" support for Blender 4.0 #153 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 --- CHANGELOG.md | 3 +++ .../include/blender_vscode/operators/script_runner.py | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8db89b0..4eb8727 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +### Fixed +- Fixed "Run Script" support for Blender 4.0. + ## [0.0.18] - 2023-04-02 diff --git a/pythonFiles/include/blender_vscode/operators/script_runner.py b/pythonFiles/include/blender_vscode/operators/script_runner.py index a1d022d..5cc584c 100644 --- a/pythonFiles/include/blender_vscode/operators/script_runner.py +++ b/pythonFiles/include/blender_vscode/operators/script_runner.py @@ -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: