Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Assign material ID that equal s the Face ID of an object

Assign material ID that equal s the Face ID of an object

voller
Contributor Contributor
1,470 Views
3 Replies
Message 1 of 4

Assign material ID that equal s the Face ID of an object

voller
Contributor
Contributor

I'm trying to figure out a way to cycle through an Edit Poly or Editable Poly, where each face gets assigned a Material ID that is equal to the face number. So face 1 would = Mat ID 1, face 2 = Mat ID 2, face 3 = Mat ID 3, and so on.

 

So I tried chatGPT to get started since I really don't know that much about maxscript and of course that maxscript fails. This is what it told me.

 

--get the selected object
obj = selection[1]

--cycle through each face of the object
for f = 1 to obj.numfaces do
(
--get the current FaceSelection
face = getFace obj f

--assign a material ID to the face that is the same as the face IDataChannelEngineClass
setFaceMatID obj f f
)

 

It errors at line 8 (face = getFace obj f). Is this even close to a working script?

0 Likes
Accepted solutions (2)
1,471 Views
3 Replies
Replies (3)
Message 2 of 4

voller
Contributor
Contributor
Accepted solution

I think I figured it out, it needed the polyop.setFaceMatID and it didn't need that line that errored out. If there's a more elegant way to do this, I'd be interested in learning why. Like, is there a way to do this if it is an Edit Poly modifier?

 

--get the selected object
obj = selection[1]

--set the object to Editable Poly mode
if classOf obj != Editable_Poly do
obj = convertToPoly obj

-- cycle through each face of the object
for f = 1 to obj.numfaces do
(
--assign a material ID to the Face that equals the Face number
polyop.setFaceMatID obj f f
)

 

0 Likes
Message 3 of 4

Serejah
Advocate
Advocate
Accepted solution

keep in mind that there's an error in mxs documentation and MatId isn't int, but unsigned short, thus you can't have more than 2^16 i.e. 65536 unique id values assigned.

 

for edit poly it is quite different.

it requires mod panel to be open, object to be selected, subobjectlevel to be active and all of this makes it slow

max modify mode -- required
subObjectLevel = 4 -- required
ep = $.modifiers[#Edit_Poly]

for i = 1 to ep.getnumfaces() do
(
	ep.SetSelection #Face #{}
	ep.Select #Face #{i}
	ep.SetOperation #SetMaterial
	ep.materialIDToSet = i - 1 -- zero based
	ep.Commit()	
)

 

@Swordslayeruploaded this thing to unify polyop/edit_poly operations, but I haven't used it myself

https://www.scriptspot.com/3ds-max/scripts/polymodop

0 Likes
Message 4 of 4

voller
Contributor
Contributor

This is only needed for objects with up to 4096 faces, usually far less, so it works for my needs.

 

Thank you for the help!

0 Likes