Assign Random Material ID to Selection

Written March 12th, 2011
Categories: Articles, Scripting / Programming, Textures / Materials
6 comments

Hey all,

I’ve put together the following short MaxScript to allow you to assign a random material ID to a selection in 3dsMax.  I’ll update it into a full tool if I get enough comments asking for it.

Here’s how you use it

  1. Select an edit_poly object,
  2. Select the polygons you’d like to assign random IDs to,
  3. Copy this script into a maxscript file (MaxScript > New Script…),
  4. Hit Ctrl + E to run the script.
numberOfSubMaterials = 3  -- Set the number of sub-materials here!!
originalSelection = polyop.getFaceSelection $
countOriginalSelection = originalSelection.count

for i=1 to numberOfSubMaterials do
(
	antiArray = #{1..countOriginalSelection}
	for i=1 to antiArray.count do antiArray[i] = (random 0 1) >= 1
	mergedArray = originalSelection * antiArray
	polyop.setFaceMatID $ mergedArray (random 1 numberOfSubMaterials)
)

Also, here’s another that assigns a random material/materialID to a collection of objects.

undo on
(
	newMaterial = multiMaterial numsubs:32
	for i = 1 to 32 do
		newMaterial[i].diffuse = random (color 0 0 0) (color 255 255 255)
	$.material = newMaterial

	for obj in $ do obj.material = newMaterial[random 1 32]
)

6 Responses to Assign Random Material ID to Selection

Leave a reply

Designed by Alejo "Mr. Bluesummers" Grigera"
©2014 MrBluesummers.com