# How to make an object transparent in the viewport?

I would like to make one of my objects transparent in the 3D Viewport. When I look around I get tons of answers - all different, and some of them a lot more complicated than others and also older from versions of Blender. I can't get any of them to work. I just want the simplest way to make anything transparent; like descreasing the alpha channel or checking an x-ray parameter or something like that. Any ideas?

I tried bpy.context.active_object.show_transparent=True but I'm sure what it does, but it seems like what I want.

Here are some of the links I found:

• Might be a good idea to add some reference images of what you call "transparent" and the links to the answers that weren't helpful... – brockmann Dec 8 '20 at 13:42
• You are talking about the solid view, not material preview or rendering, right ? – Gorgious Dec 8 '20 at 14:57
• Better! Related: Code to toggle viewport display material alpha I'd recommend do what ever you want to to in the GUI first, then find a way doing it with python. – brockmann Dec 8 '20 at 19:44
• but you also have to set viewport shading to "object" (@brockmann) – lemon Dec 8 '20 at 19:48
• Eurika! I have an image so that I can answer my own question. – DrDress Dec 8 '20 at 19:49

One option is to set the alpha value (fourth component) of Material.diffuse_color:

float array of 4 items in [0, inf], default (0.8, 0.8, 0.8, 0.8)

import bpy

# Get the object in context
obj = bpy.context.object

# Get the active material
mat = obj.active_material

# Set the alpha value of the diffuse color
mat.diffuse_color = (0.0 , 0.0 , 1.0 , 0.7)