JacquesLucke / blender_vscode

Visual Studio Code extension for Blender development.
MIT License
568 stars 75 forks source link

Blender 4.0 and Run Script Error from VSCode #151

Closed ericwomer closed 9 months ago

ericwomer commented 11 months ago

Blender 4.0 23e3f8f563960655ae084cbffa7defbe34f29451 Ubuntu 23.04 Python 3.10 (bundled with Blender)

After starting blender and attempting to run the script from vscode I get the following error.

  File "/home/eric/.vscode/extensions/jacqueslucke.blender-development-0.0.18/pythonFiles/include/blender_vscode/utils.py", line 22, in always
    try: func()
  File "/home/eric/.vscode/extensions/jacqueslucke.blender-development-0.0.18/pythonFiles/include/blender_vscode/operators/script_runner.py", line 24, in run_script_action
    bpy.ops.dev.run_script(context, filepath=path)
  File "/home/eric/.local/share/Blender/blender-4.0/4.0/scripts/modules/bpy/ops.py", line 106, in __call__
    C_exec, C_undo = _BPyOpsSubModOp._parse_args(args)
  File "/home/eric/.local/share/Blender/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```

The script confirms to run from the blender script editor

the script (its actually any script or addon) is as follows.

import bpy

bpy.ops.mesh.primitive_cube_add(size=4)

cube_obj = bpy.context.active_object

cube_obj.location.z = 5

Andrej730 commented 11 months ago

the old context override method bpy.ops.dev.run_script(context, filepath=path) is not supported anymore since Blender 4.0, it needs to be

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

But be careful since there is an issue with new temp override where you cannot longer use areas from other screens in override or it will produce Area not found in screen (reported it to Blender)

monnerHenster commented 10 months ago

the old context override method bpy.ops.dev.run_script(context, filepath=path) is not supported anymore since Blender 4.0, it needs to be

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

But be careful since there is an issue with new temp override where you cannot longer use areas from other screens in override or it will produce Area not found in screen (reported it to Blender)

After modifying it according to your description, the script is running successfully, thanks!

Ladvien commented 9 months ago

Hello @ericwomer and @monnerHenster,

It seems this may be fixed in the latest push, could you confirm?

https://github.com/JacquesLucke/blender_vscode/commit/55fe6bb89bcdf14bedf25b89f2176848c386e534

BadDogSkyrim commented 9 months ago

I can confirm that the latest push fixed the problem for me.

CGArtPython commented 9 months ago

Thank you @Ladvien for pointing out the fix! Thank you @BadDogSkyrim for confirming!

version 0.0.19 of the extension from 2023-12-05 should have this fix