change color in Python

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 ?

Comments

  • 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:

    theoryshawsteverugi
  • I knew how to do this by gui. I would like to change the color of an object in the scene view by python.

  • Ahh got you point ... open the Viewport Shading Dialog and switch from Material to Object and be happy with the changed color

    works great :-)

  • edited April 11

    Which results in the next question. How can this Viewport shading color be switched to object by Python?

  • 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

    theoryshawbernd
  • 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 :-)

  • edited April 12

    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'
    
    bruno_perdigaotheoryshaw
Sign In or Register to comment.