Page MenuHome

Python operator material_slot_assign() doesn't work in 2.91 alpha
Closed, ResolvedPublicBUG

Description

System Information
Operating system: Windows-10-10.0.18362-SP0 64 Bits
Graphics card: GeForce RTX 2080 SUPER/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 442.92

Blender Version
Broken: version: 2.91.0 Alpha, branch: master, commit date: 2020-09-04 21:32, hash: rBcf0ba59e311b
Worked: 2.90

Short description of error
When using the "assign" button from the UI in edit mode ("assign active material to slot" in the material properties) it works as expected, but when using bpy.ops.object.material_slot_assign() from the python console, it only outputs {'CANCELLED'} instead of {'FINISHED'} like in 2.90.

User Iceythe on Blenderartists thought it might have to do with Campbell's work on material assigning here: https://developer.blender.org/diffusion/B/browse/master/source/blender/editors/render/render_shading.c%24273

"Can confirm it worked on 2.90 alpha and does not work on 2.91. Campbell worked on the material assign operator just a week ago and most notably the line 273 is a call to a function that tries to fetch objects based on “context.area” being the properties editor.
You can override with area set to the properties editor, but I’d call that a regression in any case."//

Exact steps for others to reproduce the error

  • startup blend
  • make a second material slot for the default cube (with a new material also), leave the new slot selected
  • go to edit mode, select 1 face
  • switch to scripting workspace
  • type bpy.ops.object.material_slot_assign() to the console, hit enter
  • the face doesn't get assigned to the 2nd material slot

Event Timeline

bpy.ops.object.material_slot_assign() is one of the operators that requires to be called in a specific context.
When called on the console, it does not decide which scene, view3d, objects to use in the operation.
It is possible to get around this, but the bug tracker is not the right place to talk about it.

For help using Blender, please try one of the community websites: https://www.blender.org/community/

Germano Cavalcante (mano-wii) reopened this task as Confirmed.Fri, Sep 11, 4:18 PM
Germano Cavalcante (mano-wii) removed Germano Cavalcante (mano-wii) as the assignee of this task.
Germano Cavalcante (mano-wii) changed the subtype of this task from "Report" to "Bug".

In the second analysis, this used to work.
Perhaps now it is a limitation, but since it is a regression I think it is worth taking a look.

Regression introduced in rB1a650fdcb286ad3759c65a9952aa2e02966eba0b