Notifications
Clear all

[Closed] Get material slot index

I’m trying to figure out how to get the slot index of a material assigned to a selected object. I can easily get the name (via selection[1].material.name), or change things with a specified index, but can’t find a way to get the index value in the first place.

Help?

3 Replies

If you mean Material editor slots: there’s not a whole lot of them, why not just get your material from the object and loop through the medit slots doing a == comparison to find which one it is (if any)?

(
	local found = 0
	local objMat = selection[1].mat 
	for i = 1 to meditMaterials.count where found == 0 do 
		if meditMaterials[i] == objmat then found = i
	found -- contains the index of the material slot, or 0 if it was not found
)

[edit]Please ignore this, see PiXeL_MoNKeY’s reply.

Look up the material library page in the maxscript help and you will find:

findItem <mat_lib> <material>
Returns the index of the material in the material library or zero if the material is not in the material library.

finditem meditmaterials selection[1]

-Eric

Thanks for the help guys, problem solved.