bpy.ops.screenshot() provoke error if python script is called as command line argument #51983
Labels
No Label
Interest
Animation & Rigging
Interest
Blender Cloud
Interest
Collada
Interest
Core
Interest
Documentation
Interest
Eevee & Viewport
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
Import and Export
Interest
Modeling
Interest
Modifiers
Interest
Nodes & Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds, Tests & Devices
Interest
Python API
Interest
Rendering & Cycles
Interest
Sculpt, Paint & Texture
Interest
Translations
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Meta
Good First Issue
Meta
Papercut
Module
Add-ons (BF-Blender)
Module
Add-ons (Community)
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender-addons#51983
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
System Information
Ubuntu 16.04, Intel HD Graphics 530
Blender Version
Broken: 2.78.c (from ppa)
Broken: 2.76 (from Ubuntu repos)
Short description
When Blender is launched from command line, with "--python" option (with ou without "--background" option), script is executed before UI is ready so ops like screenshot cannot be made while the same code works when running within Blender !
Exact steps to reproduce the error
Working:
1/ Start Blender (from shortcut, toolbar or Ubuntu dash)
2/ Load attached screenshot.blend (minimalistic file with python script embedded inside)
3/ Switch to "Scripting" screen layout
3/ Click "Run Script" : Warning is emitted but screenshot is generated and stored in your $HOME directory (since provided path is "." as second parameter of my own screenshot() call)
(didn't find the way to fix this last warning)
Working:
1/ From your terminal, call
(see blend file attached)
2/ Switch to "Scripting" screen layout
3/ Click "Run Script" : same warning is emitted but screenshot is generated and stored in current directory
NOT working:
1/ From your terminal, call
(see attached file, same code as the one embedded in the provided blend file)
2/ A screenshot is generated containing an empty window filled with default color (gray by default)
NOT working: (alternative with same result as previous one)
1/ From your terminal, call
2/ A screenshot is generated containing an empty window filled with default color
NOT working:
1/ From your terminal, call
2/ Crash, no screenshot generated
(unable to find what is incorrect in the context, probably associated to the fact the UI is not ready when script is executed)
NOT working : (by the way)
If you uncomment the code trying to find a workaround playing with applications handlers (at bottom of provided file or inside Text editor), you'll find that load_pre or load_post are not raised when blender is called with a script from command line !
Thanks for your work. Blender is great, I'm trying to use it as an alternative to limited solution like OpenScad. I would like to be able to customize the UI to have a multiaxis view and make screenshots of the full window (or some areas depending on scenario) to "debug" 3D printed objects, being able (example) to "see" / check (step by step + different view angles) if the selected edge loop is the good one before extrusion and by "selection" I mean the edges highligthed (selected) before manipulation (so rendering and saving it is not a valid alternative). Not to mention the fact that fixing this bug can help a lot to automatize screen capture for tutorials !
screenshot.blend screenshot.py
Changed status to: 'Open'
Added subscriber: @ntuxer
Added subscriber: @Sergey
Changed status from 'Open' to: 'Archived'
The warning is caused by script trying to trick the system and override the context, that context is likely in inconsistent state. When running screenshot from the interface you don't need to override any of the contexts.
All the scripts passed via command line argument are executed at command line processing time, prior to any OpenGL draw is done. The screenshot operator itself is just reading OpenGL buffer,m without doing any actual drawing (it can't draw anything since that'd be unsafe).
When running blender in background mode, there is no window created, which also means there is no OpenGL context. You can;t use screenshot in such configuration.
So thanks for the report, but it's just limitation which can not be easily bypassed.
Thanks for your answer but, forgetting "--background" option (1st and 2nd "NOT working" cases), why are these commands not being able to a take valid screenshot since the UI is launched and can be modified by my script as you can test if you uncomment corresponding lines (so the OpenGL buffer should be readable as you mentioned, since Blender is not started in background) ?
As mentioned above, UI is launched but is not being drawn at the time when your script runs.
Thanks for your precision