Notifications
Clear all

[Closed] How to: Select and delete faces by MatID

I’m a total MXS idiot.

I need a script that would delete faces (from Edtiable Meshes AND Editable Polys) based on their MatID. In my case, I’d like to delete faces with MatID 2.

I’ve copied the output from the macrorecorder and put that into this script:

for i in selection do
(
macros.run "Modifiers" "Mesh_Select"
subobjectLevel = 4
$.modifiers[#Mesh_Select].materialID = 2
macros.run "Modifiers" "DeleteMesh"
)

It will set the Meshselect Modifier ID to 2 but it won’t select those faces, so the Delete Mesh modifier deletes whatever was selected in the base object (or the whole object if nothing was selected).

How do I actually select faces with whatever ID is specified?

Also, this one only works with one object, how to wrap it in a way so it works if more than one object is selected?

Thanks in advance.

5 Replies
(
 	if selection.count != 0 then
 	(
 		max modify mode
 		for obj in selection as array do
 		(
 			select obj
 			ms = (Mesh_Select ())
 			addModifier obj ms ui:on
 			meshFaceCount = getNumFaces $
 			subobjectlevel = 4
 			faces = for f in 1 to meshFaceCount where (getFaceMatID obj f) == 2 collect f
 			setFaceSelection obj ms faces
 			modPanel.addModToSelection (DeleteMesh ())
 		)
 	)
 	else
 		messagebox "Select some objects" title:"miauu Script Error!!!"
 )

Great, thank you so much. I really need to dive into MXS at some point, it makes life just a lot easier.

One question: I noticed that the MeshSelect modifier selects ID2 but still displays ID1 in the ‘Select by Mat ID’ field. Is this a limitation of how UI and MXS are linked to each other or a bug? Using max 2012 btw.

In my code MeshSelect modifier does not select faces with matID =2. This line:

faes = for f in 1 to meshFaceCount where (getFaceMatID obj f) == 2 collect f

collect all faces with matID =2, and this line select them:

setFaceSelection obj ms faces 

Look at the maxscript reference for “getFaceSelection”.

there are two basic ways how to delete faces by their ID.
One way is to use meshop/polyop interface…


 fn deleteMeshFacesByMatID_Mesh node matID:1 = if iskindof node Editable_Mesh do
 (
 	if canconvertto node Editable_Mesh do converttomesh node
 	faces = for f=1 to node.numfaces where (getFaceMatID node f) == matID collect f
 	meshop.deletefaces node (faces as bitarray)
 	update node
 )
 

Another way is to use modifiers…


 fn deleteMeshFacesByMatID_Modi node matID:1 = 
 (
 	addmodifier node (VolumeSelect level:2 volume:5 matID:matID)
 	addmodifier node (DeleteMesh())
 )
 

the mixing of these two methods is not a good practice.

Thank you both for your help (and sorry for the late reply)!