getFaceSelection doesn't work as expected

I'm trying to select only faces with material ID = 1 in my object.

512 is the total number of the object
381 is the number of faces with mat ID = 2
131 is the number of faces with mat ID = 3

so I wrote this:

$.selectByMaterial 2
polyList = getFaceSelection $
print polyList.count

What I obtain is "512"...but with the object still selected, if I click the polygon subselection button, there are 381 faces selected.

So, where I'm wrong?

From Maxscript help:

getFaceSelection [ ] [name: ]

getFaceSelection

Retrieves the face selection set, or the specified named selection set if the optional name: parameter is specified, as a BitArray. See the getVertSelection() method for more information.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

..

Your code works properly, but at the end the polyList is bitarray and not array. So, to get the count of the faces you have to use
print polyList.numberset
and not .count. Go to bitarray topic in maxscript help file and you will see the difference between .count and .numberset properties.

You can use this instead of your code.

(
	local curO = selection[1]
	local matID = 2
	if classof curO == Editable_Poly do
	(
		local allFacesCount = polyop.getNumfaces curO
		local faces = for f = 1 to allFacesCount where (polyop.getFaceMatID curO f) == matID collect f
		polyop.setFaceSelection curO faces
	)
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.