temp_override() not always setting the context #100664

Open
opened 2022-08-27 10:24:26 +02:00 by Jan Kadeřábek · 10 comments

System Information
Operating system: Windows-10-10.0.19044-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 3060 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 512.15

Blender Version
Broken: version: 3.2.1, branch: master, commit date: 2022-07-05 15:44, hash: a2d59b2dac
Worked: Didn't work in earlier releases either

Short description of error
temp_override() is currently difficult to use, because it for example sets the context for

ops.object.delete()

but not for

ops.object.convert()

I also couldn't get it work for setting active_layer_collection and others.

Exact steps for others to reproduce the error

temp_override_limited.blend

  • Open the attached .blend
  • Run the included script which overrides the context to Cube2 and performs ops.object.convert()
  • Context error is thrown
  • Comment the ops.object.convert() line & uncomment ops.object.delete(), run again

Cube2 is deleted

**System Information** Operating system: Windows-10-10.0.19044-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 3060 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 512.15 **Blender Version** Broken: version: 3.2.1, branch: master, commit date: 2022-07-05 15:44, hash: `a2d59b2dac` Worked: Didn't work in earlier releases either **Short description of error** *temp_override()* is currently difficult to use, because it for example sets the context for ``` ops.object.delete() ``` but not for ``` ops.object.convert() ``` I also couldn't get it work for setting *active_layer_collection* and others. **Exact steps for others to reproduce the error** [temp_override_limited.blend](https://archive.blender.org/developer/F13420504/temp_override_limited.blend) - Open the attached .blend - Run the included script which overrides the context to *Cube2* and performs *ops.object.convert()* - Context error is thrown - Comment the *ops.object.convert()* line & uncomment *ops.object.delete()*, run again # Cube2 is deleted

Added subscriber: @JanKaderabek

Added subscriber: @JanKaderabek
Member

Added subscriber: @PratikPB2123

Added subscriber: @PratikPB2123
Member

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'
Member

Thanks for the report.
object_convert_poll() function was failing because active object was null in your case. Either set active object by clicking on it in viewport or do it from python api
Does this script works for you?:

from bpy import context

obj = bpy.data.objects["Cube2"]

obj.select_set(True)
context.view_layer.objects.active = obj

with bpy.context.temp_override(object = obj, selected_objects = [obj]):

bpy.ops.object.convert(target='MESH')

    - bpy.ops.object.delete()```
Thanks for the report. `object_convert_poll()` function was failing because active object was null in your case. Either set active object by clicking on it in viewport or do it from python api Does this script works for you?: ```import bpy from bpy import context obj = bpy.data.objects["Cube2"] obj.select_set(True) context.view_layer.objects.active = obj with bpy.context.temp_override(object = obj, selected_objects = [obj]): ``` bpy.ops.object.convert(target='MESH') ``` - bpy.ops.object.delete()```

Added subscriber: @ideasman42

Added subscriber: @ideasman42

In #100664#1409258, @PratikPB2123 wrote:
Either set active object by clicking on it in viewport or do it from python api

Hi Pratik,
but that's what temp_override() should do.
If you run the script with bpy.ops.object.delete(), you can see the context (active / selected object) is set correctly and the script runs without any error (Cube2 gets deleted).
But for whatever reason it doesn't work for convert() and more, which looks like a bug.
@ideasman42 suggested to report it in the comment here https://developer.blender.org/rBf438344cf243632e497772cf1f855b9c8856fd37#351220, so I have created the task.

> In #100664#1409258, @PratikPB2123 wrote: > Either set active object by clicking on it in viewport or do it from python api Hi Pratik, but that's what *temp_override()* should do. If you run the script with *bpy.ops.object.delete()*, you can see the context (active / selected object) is set correctly and the script runs without any error (Cube2 gets deleted). But for whatever reason it doesn't work for *convert()* and more, which looks like a bug. @ideasman42 suggested to report it in the comment here https://developer.blender.org/rBf438344cf243632e497772cf1f855b9c8856fd37#351220, so I have created the task.
Member

Changed status from 'Needs User Info' to: 'Needs Developer To Reproduce'

Changed status from 'Needs User Info' to: 'Needs Developer To Reproduce'

Just informing that it seems to be the case also with transform_apply().

Just informing that it seems to be the case also with transform_apply().

To add my 2 cents, I don't think ops.object.convert not being overridable is tied to the new syntax, devs have confirmed that this particular operator can't be fully overriden.

It was already the case with the old, dictionary syntax. see https://developer.blender.org/T93188

To add my 2 cents, I don't think `ops.object.convert` not being overridable is tied to the new syntax, devs have confirmed that this particular operator can't be fully overriden. It was already the case with the old, dictionary syntax. see https://developer.blender.org/T93188
Philipp Oeser removed the
Interest
Python API
label 2023-02-10 09:04:24 +01:00

I'm also finding some issues with temp_override not setting the context - unless I'm misunderstanding.

Try running the script in the attached file. If it was working as expected (as far as I understand it) the context override would apply the modifiers on the object called this is the one that should get modifiers applied! but instead it gets applied to This should NOT have modifiers applied, which is what we'd expect if context override were not working properly, right?

I'm also finding some issues with temp_override not setting the context - unless I'm misunderstanding. Try running the script in the attached file. If it was working as expected (as far as I understand it) the context override would apply the modifiers on the object called `this is the one that should get modifiers applied!` but instead it gets applied to `This should NOT have modifiers applied`, which is what we'd expect if context override were not working properly, right?
Sign in to join this conversation.
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
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#100664
No description provided.