[Closed] For loop with materials
Is there a way to use a for loop to cycle through a selection of objects and randomly apply different (pre-made) materials to the objects? Ideally, i would actually make the materials in the interface and then call the names or variable names in the loop. Thinking about using a single character proxy model instanced a bunch of times and then varying the materials to generate a crowd. Any help will be really, really appreciated!
Yeah, that’s pretty easy on a basic setup… this should get you started …oh you should look up meditMaterials and also whatever kind of material you are planning on using so you know what to change.
sel = selection as array
for o in sel do
(
newmat = copy meditMaterials[1] --copy the first material in the materialeditor
newmat.name = uniquename (o.name + "_mat") --change the name
newmat.diffusecolor = color (random 0 255) (random 0 255) (random 0 255) --change the color
o.material = newmat --assign the new material
)
I was thinking of…well lets say that i created 3 materials in the first three slots…called mat_1, mat_2 and mat_3 and i have 30 objects in the scene. The mats are setup how i want/need them and basically i want to select the 30 objects and have the for loop randomly apply mat_1, mat_2 and mat_3 to the 30 objects. Do the three mats (or whatever number of mats) need to go into an array to be assigned randomly to the selection array? It seems logical and simple in my head but problematic getting it to work! Thanks for the input guys!