Python API : OBJECT_OT_convert can't be fully abstracted from context with override #93188
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
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
5 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#93188
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
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
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: NVIDIA GeForce GTX 1660 SUPER/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 472.39
Blender Version
Broken: version: 2.93.5, branch: master, commit date: 2021-10-05 12:04, hash:
a791bdabd0
It didn't work in latest Beta build either.
Worked: I don't think it ever worked otherwise ?
Short description of error
Overriding the context of an operator with a dictionary enables us to call them from pretty much anywhere in the code without having to make sure the context is correct (selected objects, active object, called from a particular editor, etc.)
However the
OBJECT_OT_convert
called withbpy.ops.object.convert
operator still requires an active object to be selected to function with an override, which defeats the purpose of using an override.It is explained quite thoroughly in this BSE Q&A https://blender.stackexchange.com/a/235048/86891
Exact steps for others to reproduce the error
Script to reproduce in an empty file :
Added subscriber: @nathan.hild
I can add that
bpy.ops.object.join
has the same limitation :This works :
This doesn't :
Related thread on BSE https://blender.stackexchange.com/a/243663/86891
Added subscriber: @lichtwerk
Join
relies onselected_editable_objects
, this works:Oh, my bad, thanks for the clarification. :)
Is there a similar context override that I've missed for
Convert
?Changed status from 'Needs Triage' to: 'Needs Developer To Reproduce'
Added subscriber: @dr.sybren
Regarding the
Convert
operator: I think it's true, this cannot be fully abstracted with override context.Instead of relying on
Object
only, this operator takes into account theBase
(which is kind of an abstraction ofObject
that can handle stuff like selection or visibilty in different viewlayers).Doing this is useful, because it can then handle the needed stuff on the Base & new Base properly when a new converted object is created.
And afaict, python does not have access to this
Base
"stuff".I dont actually think it is absolutely mandatory that this operator works this way (I think it could first rely on
Object
only -- and only later handle theBase
as well -- which could make the whole usecase of this report possible), however, I am unsure if this could be called a bug (dont think it is, it is probably just a limitation of this particular operator -- and there are workarounds using python differently here).Since @dr.sybren would probably know this in more depth (and would know if there is some sort of guideline or "promised support" of overriding context): could this be called a bug?
Any updates on this issue? Met this one on Blender 3.6.
This also applies to
bpy.ops.object.convert
: it relies onselected_editable_objects
. Furthermore, for current Blender versions you'll want to do the context override differently:And having said all that, it still won't work because the C code has a check for
base_act->flag & BASE_SELECTED
in there; in other words, the active object has to be marked as selected. It doesn't test whether the object is part ofselected_editable_objects
, but rather it tests that the object itself is selected. And so that's what you have to ensure to make it work.The code doesn't rely on the active object much, it only does so in two places:
I think the former could be a bug, as it should check the type of the object that's being converted, rather than the active object (the active one could be a mesh, and the selection could include metaballs). The latter shouldn't completely stop the conversion either, as if there is no active object before, it's fine if there is no active object afterwards.
This issue still occurs in 4.0.2. Is the fact that it cannot be used with
context.temp_override
not considered a bug? Reading Sybren's reply above I don't quite understand why the check for the object to be marked selected, rather than be inselected_editable_objects
cannot be changed.Thanks for re-testing before writing here :)
I don't think so, I'm not aware of any requirement that operators should be fully overridable with
context.temp_override
. Of course it would be nice, but I don't think that requirement is there now.I'm wondering what the reason is you're using this operator to begin with. Metaballs and Surfaces can be converted to mesh by calling
the_object.to_mesh()
. Granted, that mesh then might need some special handling (because it's an evaluated one, so it needs to get copied before you can assign it to another object), but at least it doesn't require anything in terms of overrides, selection state, etc.PS: don't get me wrong, I'm not pushing back against your needs & frustrations. I'm merely trying to paint a more complete picture, and asking questions to figure out your exact needs.