Python UI inconsistent with the documentation #113732
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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#113732
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?
Blender Version
Broken: 3.6.1
Worked: NA
When baking a texture using Python, the following code correctly bakes the normal map:
import bpy
bpy.ops.object.bake(type='NORMAL')
On the other hand, the following does not work:
import bpy
bpy.context.scene.cycles.bake_type = 'NORMAL'
bpy.ops.object.bake()
But as you can see in the image, the interface is telling us to write "bpy.context.scene.cycles.bake_type = 'NORMAL'"
Calling
bpy.ops.object.bake()
will use the default value of itstype
argument which is'COMBINED'
.Setting
scene.cycles.bake_type
changes thetype
argument of thebpy.ops.object.bake
operator that is displayed in the UI: https://projects.blender.org/blender/blender/src/branch/blender-v3.6-release/intern/cycles/blender/addon/ui.py#L1928Hovering the mouse over with Bake button shows the
type
argument:No bug here as far as I can tell.
I think I understand what the problem is, let me explain.
I should have mentioned that "type" is the only parameter that works like that. For all the other parameters, modifying what is displayed in the UI affects bpy.ops.object.bake(). In the documentation https://docs.blender.org/api/current/bpy.ops.object.html, we have the following:
bpy.ops.object.bake(type='COMBINED', pass_filter={}, filepath='', width=512, height=512, margin=16, margin_type='EXTEND', use_selected_to_active=False, max_ray_distance=0.0, cage_extrusion=0.0, cage_object='', normal_space='TANGENT', normal_r='POS_X', normal_g='POS_Y', normal_b='POS_Z', target='IMAGE_TEXTURES', save_mode='INTERNAL', use_clear=False, use_cage=False, use_split_materials=False, use_automatic_name=False, uv_layer='')
In the description of the parameters, nothing tells us that the "type" parameter works differently than all others.
Write now we have to write the following:
import bpy
bpy.context.scene.cycles.bake_type = 'NORMAL'
bpy.context.scene.render.bake.normal_g = 'NEG_Y'
bpy.context.scene.render.bake.use_selected_to_active = True
For example, "bpy.context.scene.render.bake.normal_g" modifies the UI dropdown, and it does not need to be written again inside bpy.ops.object.bake().
The paramater "type" is the only one that needs to be inside bpy.ops.object.bake().
Shouldn't it be "bpy.context.scene.render.bake_type" instead of "bpy.context.scene.cycles.bake_type"?
So "render" instead of "cycles"?
"bpy.context.scene.cycles" I think was used in older Blender versions, as you can see here: https://docs.blender.org/api/2.80/bpy.types.CyclesRenderSettings.html
Hmm, I wouldn't have expected that calling
bpy.ops.object.bake()
would use any of thebpy.context.scene.render.bake.normal_g
and similar properties because the default execution context for Operators called from code is'EXEC_DEFAULT'
which does not callinvoke
functions.Looking at the source, both the
execute
andinvoke
functions callbake_set_props()
. I think it may be a bug that theexecute
function also callsbake_set_props()
.Rather than the
type
argument being the argument with odd behaviour, I think it would be better to say that all the other arguments are the ones with odd behaviour because their default values are ignored and instead replaced by values frombpy.context.scene.render.bake
.Call in
execute
:Call in
invoke
:I agree.
And shouldn't bake_type be inside "bpy.context.scene.render" or "bpy.context.scene.render.bake" instead of "bpy.context.scene.cycles"?
Because CyclesRenderSettings is inside Blender 2.8 documentation: https://docs.blender.org/api/2.80/bpy.types.CyclesRenderSettings.html
But it is not inside Blender 3.6 documentation: https://docs.blender.org/api/current/bpy.types.html
I think
bpy.ops.object.bake()
should bake with default arguments (i.e. type=combined and other default parameters)@lichtwerk , any idea about the expected result?
I am not sure if there is a general rule in regards to fetching operator properties (in case they are not specifically provided in the operator call as argument) from elsewhere (e.g. scene properties / tool settings) or if this only meant to be done in
ot->invoke()
Looking at code,
!RNA_property_is_set
is usually done in invoke, but there are occasions if it being done inot->exec
as well, e.g.:ot->invoke
WM_menu_invoke, could be made specific)ot->invoke
WM_menu_invoke, could be made specific)ot->invoke
though)ot->invoke
though)ot->invoke
though)ot->invoke
though)Executing one of the above operators will never really use defined defaults (when not specifying them specifically, but instead use e.g. scene properties / tool settings).
Not a big deal, but it would seem more consistent/correct to reserve for
invoke
If there is the need to use the same function (e.g.
bake_set_props()
as reported in #113732) maybe we could checkOP_IS_INVOKE
flag and otherwise still get defaults with something likeRNA_property_XXXtypeXXX_get_default
?Will ask around
In the case of #113732 I think it makes sense to treat
type
the same as all other properties (initializing it from the scene).Only initializing from tool-settings/scene properties from invoke & not exec seems like it might be a good rule of thumb although it would need to be tested.
It could be impractical at times:
There are cases when we use
exec
from menus for e.g (to avoid being prompted for options). This might end up forcing the menu item to copy properties from tool-settings in a way thats awkward and could even cause key-shortcuts not to show... so it could be OK to checkOP_IS_INVOKE
and only set properties in this case - it's more something to investigate as far as I can see.