Notifications
Clear all

[Closed] Slow MaterialID assigner script

Hello guys, I’m fiddling with MaxScript and needed to write one that assigned a unique MatID to every object selected. If I select 15 Objects it would assign a MatID from 1 to 15 to each one of them so every object would end up having a unique MatID.

I’ve come up with this, which runs terribly slow! Please take lightly on me!

(a = selection as array
for i=1 to selection.count do
	(
		select a[i]
		subobjectLevel = 5
		max select all
		$.EditablePoly.setMaterialIndex i 1
		max select none
		subobjectLevel = 0
		)
	)

I was thinking about making another one that would just add a Material Modifier with a unique ID to each object and then collapse the stack – is this a better idea?

Cheers and thanks a lot!

4 Replies

all that selecting and de-selecting makes it slow.

(
	a = selection as array
	for i=1 to selection.count do polyop.setFaceMatID a[i] #all i
)

Better if it checks whether the objects are editable polys.

(
	a = selection as array
	for i=1 to selection.count where isKindOf a[i] editable_Poly do polyop.setFaceMatID a[i] #all i
)

how about something like

id = 1;
for i in $selection do 
(	
	addModifier i (materialModifier materialID:id)
	id += 1
)

Great! Thank you very much Raytracer and Claude! Everything works much faster now! Got loads of scripting to learn!!