Custom data split normals are taking active object from the area even if the active object is overriden #106612

Open
opened 2023-04-06 07:35:34 +02:00 by Andrej · 4 comments
Contributor

Blender 3.5

Short description of error

Operators customdata_custom_splitnormals_add and customdata_custom_splitnormals_clear if called from properties panel seem to take active object from currently active area even if you context.temp_override(object=obj) or context.view_layer.objects.active = obj to change active object which is counterintuitive and contradicts with how other operators active object override work.

Found a workaround - if you context.temp_override(area=None, object=obj) it will take active object into account.

Exact steps for others to reproduce the error

  1. Open attached .blend file
  2. Run the script
  3. (Make sure all objects are selected)
  4. Go to Custom Split Normals section (in Object Data Properties after Geometry Data).
  5. Try "Add CSN" - it wouldn't work
  6. Try "Add CSN override area" - it doesk work.
Blender 3.5 **Short description of error** Operators `customdata_custom_splitnormals_add` and `customdata_custom_splitnormals_clear` if called from properties panel seem to take active object from currently active area even if you `context.temp_override(object=obj)` or `context.view_layer.objects.active = obj` to change active object which is counterintuitive and contradicts with how other operators active object override work. Found a workaround - if you `context.temp_override(area=None, object=obj)` it will take active object into account. **Exact steps for others to reproduce the error** 1. Open attached .blend file 2. Run the script 3. (Make sure all objects are selected) 4. Go to Custom Split Normals section (in Object Data Properties after Geometry Data). 5. Try "Add CSN" - it wouldn't work 6. Try "Add CSN override area" - it doesk work.
Andrej added the
Priority
Normal
Status
Needs Triage
Type
Report
labels 2023-04-06 07:35:35 +02:00
Iliya Katushenock added the
Interest
Python API
label 2023-04-06 14:56:35 +02:00

You need to overwrite "mesh".

context.temp_override(mesh=obj.data, object=obj)

I don't know why overriding the "area" removes the keyword "mesh".
@ideasman42 can you shed some light?

You need to overwrite "mesh". ``` context.temp_override(mesh=obj.data, object=obj) ``` I don't know why overriding the "area" removes the keyword "mesh". @ideasman42 can you shed some light?
Germano Cavalcante added
Status
Needs Info from Developers
and removed
Status
Needs Triage
labels 2023-04-06 19:13:38 +02:00
Member

mesh.customdata_custom_splitnormals_add and mesh.customdata_custom_splitnormals_clear use ED_mesh_context to get the mesh to operate on, which first attempts to get the "mesh" from the current context. You should be able to override "mesh" to the bpy.types.Mesh that you want to operate on to achieve your desired results.

If there's no "mesh" in the current context, it falls back to getting the Object with ED_object_active_context which tries to get it from "object" if it exists (ED_object_context) or then falls back to "active_object" if it exists (CTX_data_active_object).

There's basically no rhyme nor reason to how each operator gets what to operate on from the current context, some will prefer "object", some will prefer "active_object", some will get the active object directly from the "view_layer" or you might have something different like "mesh" in this case. You will have to look up the source code of the operator every time that you want to use a context override.

`mesh.customdata_custom_splitnormals_add` and `mesh.customdata_custom_splitnormals_clear` use `ED_mesh_context` to get the mesh to operate on, which first attempts to get the "mesh" from the current context. You should be able to override "mesh" to the `bpy.types.Mesh` that you want to operate on to achieve your desired results. If there's no "mesh" in the current context, it falls back to getting the Object with `ED_object_active_context` which tries to get it from "object" if it exists (`ED_object_context`) or then falls back to "active_object" if it exists (`CTX_data_active_object`). There's basically no rhyme nor reason to how each operator gets what to operate on from the current context, some will prefer "object", some will prefer "active_object", some will get the active object directly from the "view_layer" or you might have something different like "mesh" in this case. You will have to look up the source code of the operator every time that you want to use a context override.
Author
Contributor

Thanks for the insight, never seen overriding mesh parameter before. Never thought there is such option because usually mesh is not an attribute of https://docs.blender.org/api/current/bpy.types.Context.html

>>> bpy.context.mesh
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
AttributeError: 'Context' object has no attribute 'mesh'

But if you check it from the operator that was executed from properties panel it's indeed there.

>>> print('mesh context', bpy.context.mesh)
mesh context <bpy_struct, Mesh("Cube.004") at 0x000001CD2C830108>
Thanks for the insight, never seen overriding `mesh` parameter before. Never thought there is such option because usually `mesh` is not an attribute of https://docs.blender.org/api/current/bpy.types.Context.html ``` >>> bpy.context.mesh Traceback (most recent call last): File "<blender_console>", line 1, in <module> AttributeError: 'Context' object has no attribute 'mesh' ``` But if you check it from the operator that was executed from properties panel it's indeed there. ``` >>> print('mesh context', bpy.context.mesh) mesh context <bpy_struct, Mesh("Cube.004") at 0x000001CD2C830108> ```
Member

Thanks for the insight, never seen overriding mesh parameter before. Never thought there is such option because usually mesh is not an attribute of https://docs.blender.org/api/current/bpy.types.Context.html

https://docs.blender.org/api/current/bpy.context.html gives a more complete list of the context members that are available in different contexts.

> Thanks for the insight, never seen overriding `mesh` parameter before. Never thought there is such option because usually `mesh` is not an attribute of https://docs.blender.org/api/current/bpy.types.Context.html https://docs.blender.org/api/current/bpy.context.html gives a more complete list of the context members that are available in different contexts.
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
3 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#106612
No description provided.