B
by bernd on 11 Apr 2024, edited 12 Apr 2024
#
I would like to change the color of the object in the scene by python ...
All the following works very well ...
from blenderbim.bim.ifc import IfcStore
obj = IfcStore.get_element("some_guid")
obj.type
obj.name
obj.hide_set(True) # hide
obj.hide_set(False) # show
obj.visible_get() # get visibility
obj.select_set(True) # select
obj.select_set(False) # unselect
but with this nothing happens to the object ...
obj.color = [1.0, 1.0, 0.0, 1]
Am I missing something ?
B
by bruno_perdigao on 11 Apr 2024
#
+2 votes
Maybe it's working, but you are not seeing, check if Viewport Shading color is set to "Object". You can also inspect in Object Properties > Viewport Display:

B
by bernd on 11 Apr 2024
#
I knew how to do this by gui. I would like to change the color of an object in the scene view by python.
B
by bernd on 11 Apr 2024
#
Ahh got you point ... open the Viewport Shading Dialog and switch from Material to Object and be happy with the changed color
works great :-)
B
by bernd on 11 Apr 2024, edited 11 Apr 2024
#
Which results in the next question. How can this Viewport shading color be switched to object by Python?
B
by bruno_perdigao on 11 Apr 2024
#
+2 votes
The short answer would be:
for area in bpy.context.screen.areas: # iterate through areas in current screen
if area.type == 'VIEW_3D':
for space in area.spaces:
if space.type == 'VIEW_3D':
space.shading.color_type = 'OBJECT'
It gets trickier if you have more than one viewport and would like to change just a specific one
B
by bernd on 12 Apr 2024
#
works great here ... :-)
@bruno_perdigao said:
It gets trickier if you have more than one viewport and would like to change just a specific one
Thus ... If I switch from BIM to scripting copy the code it changes the viewport above Python widget, but not the main viewport if switch back to BIM. I am fine with this ATM :-)
G
by Gorgious on 12 Apr 2024, edited 12 Apr 2024
#
+2 votes
You can query viewports in all the workspaces at once :
import bpy
for ws in bpy.data.workspaces:
for screen in ws.screens:
for area in screen.areas:
if area.type == 'VIEW_3D':
for space in area.spaces:
if space.type == 'VIEW_3D':
space.shading.color_type = 'OBJECT'
# Or if you want only the BIM workspace
ws = bpy.data.workspaces.get("BIM")
if ws:
for screen in ws.screens:
for area in screen.areas:
if area.type == 'VIEW_3D':
for space in area.spaces:
if space.type == 'VIEW_3D':
space.shading.color_type = 'OBJECT'