Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete is skipped #68

Closed
CarstenHoyer opened this issue Mar 23, 2020 · 2 comments
Closed

Delete is skipped #68

CarstenHoyer opened this issue Mar 23, 2020 · 2 comments

Comments

@CarstenHoyer
Copy link

This simple script works from Blender (selects everything, deletes everything, inserts a camera), but fails from VS code - in the sense that it does select everything, and it also inserts a camera, but it doesn't perform the delete operation.

import bpy

bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)
bpy.ops.object.camera_add(enter_editmode=False, align='VIEW', location=(55,55,60), rotation=(0,0,0))

@CarstenHoyer
Copy link
Author

Here is a workaround:

bpy.ops.object.select_all(action='SELECT')
for obj in bpy.context.selected_objects:
    if obj.type == 'MESH':
      bpy.data.meshes.remove(obj.data)
    bpy.data.objects.remove(obj)    

CGArtPython added a commit to CGArtPython/blender_vscode that referenced this issue Jan 8, 2023
…e when run from VS Code Extension JacquesLucke#135

# Summary of issue
Calling a script via operator results in an empty context.

# Related devtalk.blender
from @JacquesLucke
https://devtalk.blender.org/t/how-to-run-a-script-from-outside-blender-script-live-link-addon/9792/3?u=jacqueslucke

# Solution
Use bpy.app.timers to register a function to run the target script.

# Changes
pythonFiles\include\blender_vscode\operators\script_runner.py
* remove the RunScriptOperator and move the contents of the execute method into a the `run_script()` function
* register a timer callback to the `run_script()` function that will execute the target script

# Potentially related issues
* When adding objects to collections the objects only show after the script ends. JacquesLucke#101
* accessing bpy.context.object crashes Blender JacquesLucke#86
* Crash when adding mesh JacquesLucke#63
* Delete is skipped JacquesLucke#68

# Testing
* execute a simple script that uses `bpy.context.active_object`
* set the #context.area:   SEQUENCE_EDITOR and run this script https://github.com/CGArtPython/blender_plus_python/blob/main/sequence_editor_frame_import/sequence_editor_frame_import_done.py
* execute the script from issue JacquesLucke#101 JacquesLucke#101
* execute the script from issue JacquesLucke#86 JacquesLucke#86
* execute the script from issue JacquesLucke#63 JacquesLucke#63
* execute the script from issue JacquesLucke#68 JacquesLucke#68
* execute the script from issue JacquesLucke#41 JacquesLucke#41
CGArtPython added a commit to CGArtPython/blender_vscode that referenced this issue Apr 2, 2023
…e when run from VS Code Extension JacquesLucke#135

# Summary of issue
Calling a script via operator results in an empty context.

# Related devtalk.blender
from @JacquesLucke
https://devtalk.blender.org/t/how-to-run-a-script-from-outside-blender-script-live-link-addon/9792/3?u=jacqueslucke

# Solution
Use bpy.app.timers to register a function to run the target script.

# Changes
pythonFiles\include\blender_vscode\operators\script_runner.py
* remove the RunScriptOperator and move the contents of the execute method into a the `run_script()` function
* register a timer callback to the `run_script()` function that will execute the target script

# Potentially related issues
* When adding objects to collections the objects only show after the script ends. JacquesLucke#101
* accessing bpy.context.object crashes Blender JacquesLucke#86
* Crash when adding mesh JacquesLucke#63
* Delete is skipped JacquesLucke#68

# Testing
* execute a simple script that uses `bpy.context.active_object`
* set the #context.area:   SEQUENCE_EDITOR and run this script https://github.com/CGArtPython/blender_plus_python/blob/main/sequence_editor_frame_import/sequence_editor_frame_import_done.py
* execute the script from issue JacquesLucke#101 JacquesLucke#101
* execute the script from issue JacquesLucke#86 JacquesLucke#86
* execute the script from issue JacquesLucke#63 JacquesLucke#63
* execute the script from issue JacquesLucke#68 JacquesLucke#68
* execute the script from issue JacquesLucke#41 JacquesLucke#41
CGArtPython added a commit to CGArtPython/blender_vscode that referenced this issue Apr 2, 2023
…e when run from VS Code Extension JacquesLucke#135

# Summary of issue
Calling a script via operator results in an empty context.

# Related devtalk.blender
from @JacquesLucke
https://devtalk.blender.org/t/how-to-run-a-script-from-outside-blender-script-live-link-addon/9792/3?u=jacqueslucke

# Solution
Use bpy.app.timers to register a function to run the target script.

# Changes
pythonFiles\include\blender_vscode\operators\script_runner.py
* remove the RunScriptOperator and move the contents of the execute method into a the `run_script()` function
* register a timer callback to the `run_script()` function that will execute the target script

# Potentially related issues
* When adding objects to collections the objects only show after the script ends. JacquesLucke#101
* accessing bpy.context.object crashes Blender JacquesLucke#86
* Crash when adding mesh JacquesLucke#63
* Delete is skipped JacquesLucke#68

# Testing
* execute a simple script that uses `bpy.context.active_object`
* set the #context.area:   SEQUENCE_EDITOR and run this script https://github.com/CGArtPython/blender_plus_python/blob/main/sequence_editor_frame_import/sequence_editor_frame_import_done.py
* execute the script from issue JacquesLucke#101 JacquesLucke#101
* execute the script from issue JacquesLucke#86 JacquesLucke#86
* execute the script from issue JacquesLucke#63 JacquesLucke#63
* execute the script from issue JacquesLucke#68 JacquesLucke#68
* execute the script from issue JacquesLucke#41 JacquesLucke#41
@CGArtPython
Copy link
Collaborator

I am closing this issue.
This was resolved with this commit 621e275

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants