View Full Version : How to randomly assign material on a specific count of objects ?
02-22-2006, 10:02 AM
I search a way to randomly apply some material on some objects.
I have 54 objects and 6 materials (6x9 = 54. I guess you understand ;) )
I want to randomly select object 9 by 9 and apply a material in each time. Of course the objects that already be select and get a material can't be select again.
All of the objects already have a material on it. I think to freeze the objects i select and test the freeze to avo´d this object be selected again. And when all objects has changed material, unfreeze all.
Someone has an idea to make it ?
Thank you for your help guys :thumbsup:
02-22-2006, 12:26 PM
You can use something like this:
for i = 1 to selection.count do selection[i].material = meditMaterials[((i - 1) / 9) + 1]
02-22-2006, 01:14 PM
Oh god. :D
I think i always learn something in maxscript.
I don't know the selection[i].
Thanks a lot Light. :thumbsup:
Your help is very useful. I tell you if i success ;)
02-22-2006, 01:25 PM
That's works, that's works :D :D :D
Thank a lot Light.
Could explain me your line of code. I don't understand it a lot.
Thank you again :thumbsup:
02-22-2006, 02:18 PM
and what if I want to assign randomly to any count of object ??(imagine a crowd clothes colors)
02-22-2006, 02:53 PM
It basically loops through your current selection and assigns materials from 1 to 6. You can see that "((i - 1) / 9) + 1" creates values from 1 to 6 throughout the loop.
for i in selection do i.material = meditMaterials[random 1 24] would do what you need Laurent.
02-22-2006, 03:02 PM
ok I got it by myself, thx!
But how can I specify the material range with a spinner or something?
rollout forege "random material"
label label0d "this tool apply random materials"
label label1d " from MaterialEditor to selection."
button un " RANDOMIZER - 6 materials "
on un pressed do
(for i = 1 to selection.count do selection[i].material = meditMaterials[random 1 6.0]
button deux " RANDOMIZER - 10 materials "
on deux pressed do
(for i = 1 to selection.count do selection[i].material = meditMaterials[random 1 10.0]
button trois " RANDOMIZER - 15 materials "
on trois pressed do
(for i = 1 to selection.count do selection[i].material = meditMaterials[random 1 15.0]
createDialog forege width:220 height:130
02-22-2006, 06:11 PM
Or check the RandomMat script available here:
02-22-2006, 07:06 PM
Just add a spinner control like: spinner toVal range:[1,24,6] and then use toVal.value instead of max values like random 1 toVal.value
02-23-2006, 09:12 AM
02-23-2006, 09:12 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.