How can i get the materials of a mesh

Hi ,
i search to store the material of a mesh in a file (name and different parameters), i create a cube for exemple and i give a material at this cube.

Example of my code , i print only the material of the object and no for the mesh :

listobj = Blender.Object.Get()
for i in listobj:
if i.getType() == ‘Mesh’:
print i.getMaterials()

Take a look at:

See all the methods starting with “get” ? You can use them to get all (I suppose) material parameters. Store these in your file, then when you open your file, load parameters and use them as an argument for the equivalent “set” methods. You’ll have to create a new material.


listobj = Blender.Object.Get()
for i in listobj:
if i.getType() == ‘Mesh’:
firstmaterial = i.getMaterials()[0]

glow = firstmaterial.getAdd()
alpha = firstmaterial.getAlpha()

#put all these (glow, alpha,…) in your file


#open file, read in glow, alpha,…


Don’t feed your ego, feed the duckies…

i have look this api before post here , i search to know the material of a specific mesh . I have the name of the mesh and i would like to know it s material.
I have search and i have find only for an object and not for a mesh.

for obj in Blender.Object.Get():
    if obj.getType() == 'Mesh':
        mesh = obj.getData()
        for mat in mesh.materials:
            print mat # or whatever you want to do with mat here

I usually just access the member variable ‘materials’, but there is also a getMaterials() method for NMesh if you want empty slots returned as ‘None’ for example.