How to set material to transparent

Hi,

I’m creating an object with a mesh and a material for the mesh in this way:


        mesh = bpy.data.meshes.new("mymesh")
        obj = bpy.data.objects.new("myobj",mesh)
        material = bpy.data.materials.new("mymaterial")
        material.diffuse_color = (1.0,0.0,1.0)
        material.alpha = 0.9
        mesh.materials.append(material)
        # set location and link
        obj.location = (0,0,0)
        bpy.context.scene.objects.link(obj)
        # set mesh from python data
        mesh.from_pydata(verts,[],faces)
        mesh.update(calc_edges=True)

It should make the object a little transparent. But it doesn’t work.
The color setting works. But it doesn’t get transparent. What could be wrong?

Hi,

put code in [noparse]

paste code here

[/noparse] tags to show formatting.

There is the material use_transparency property to make it render transparent.
To display as trans in the viewport you need to set the object’s show_transparent property.


material.use_transparency = True #  renders trans
obj.show_transparent = True #  displays trans in viewport

Thanks! That did the trick.