Apply random material to element

Hi,

I found on this forum the following script that works very well when applying a random amount of materials to selected objects

Now if I have a single mesh with many sub objects in it (cubes for example) that each can be selected with the mesh / element selection, how shall I modify the script to make it apply the random materials to the elements of the mesh?

I presume the "obj" should be swtiched to become refering to the element instead?

Script:
for obj in selection do obj.material = meditMaterials[random 1 4]

thanks

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Claviateur's picture

It works thanks so much :)

It works thanks so much :)

barigazy's picture
Claviateur's picture

Thanks, I already tried this

Thanks, I already tried this one however this technique creates as many IDs as we have sub objects in a mesh but what I need is to apply a limited amount of textures (let's say 25) randomly to the subobjects. The line of script I included does just that but for independant objects and not elements of a mesh

Thanks

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.