asign a material to a custom object automatically

hi I want to add a custom object automatically with the material…

I know how to make a custom object… for example this code make a custom arrow and a custom menú:

but I want to assign a specific material to this that is in the…

I tried with different options and following the instruccion in Cookbook the

but when I add a button or menu access to the arrow that don’t have the material… :frowning:

some help please!

thanks Diego

if it has no materials yet, just append a material datablock

mat =[‘Material1’]

Otherwise get the material’s index (granted the desired material is in a material slot already) and assign it to all Polygon.material_index

me =
index = me.materials.find("Material1")
if index == -1:
    index = len(me.materials)

for poly in me.polygons:
    poly.material_index = index

someone happen in the forum but code is “invisible” :smiley:

first one is really usefull really thanks… as I did not see the code you can assign a new material to the arrow, but not one existing.

mat = ("material1") 
         mat.use_shadeless = True 
         mat.use_transparency = True 
         mat.alpha = 0.0 


also try the same code that you give me but with brackets … so not working
mat =‘Material1’) this is a … rookie mistake

thanks again … You gave me light



If you access an array of objects, use []

If you call a function or method, use ()

You can use“Material1”) if you want, but only if you don’t know for sure it exists. Instead of raising an exception, it will return None or another default value (second argument of get()).