Exercise – Randomize Material ID

This small scripts applies a Material modifier to all selected nodes and adds a random value to all of them.


--Randomize the material ID on selection...

NumberOfMultiMaterials = 8

for item in (selection as array) do (
rndVal = random 1 NumberOfMultiMaterials
--This clears already existing Material modifiers
ExistMod = for m in item.modifiers where m.name == "MyRandMat" collect m
for m in ExistMod do ( deleteModifier item m)

Mat = materialModifier name:"MyRandMat"

Mat.materialID = rndVal
AddModifier item Mat

--end script