Hello,
I'm quite new to Maxscript and I've been trying to write a simple function that will return true or false if any faces have a specified MaterialID applied to them. I got it working but only by collapsing the object into and editable_poly or editable_mesh. Ideally I would like to be able to add a modifer to the top of the stack and use that to perform the check and then remove it before the user is any the wiser. Heres what I have so far;
fn CheckForMaterialID obj index =
(
PolyList = #()
max modify mode
MatChkMod_01 = Edit_Poly()
MatChkMod_01.name = "MaterialIDCheck"
addModifier obj MatChkMod_01
subObjectLevel = 4
MatChkMod_01.selectByMaterialID = index
MatChkMod_01.selectByMaterialClear = true
MatChkMod_01.ButtonOp #SelectByMaterial
-- the script gets this far - successfully selects the polys but
-- then I'm unable to do a count of them
PolyList = polyop.getFaceSelection obj
print PolyList.count
deleteModifier obj MatChkMod_01
)
Is there any other way (cleaner or faster) of doing this?
Thanks :thumbup:
Replies
- I was trying to perform a 'count' on a bitarray which didn't yield the result I was expecting. But by converting it to a standard array (which I can see you did in your script) the 'count' function returns the number of faces selected - which is what I wanted.
Thanks for the help and I'm going to try implementing my script using the EditablePoly functions rather than the EditPoly ones like you have in your snippet of script. :-)I'll have to learn more about bitarrays in MaxScript and how to use them.
here a nice example to get a outline of a current faceselection
works pretty fast
Out of interest, why do you zero the local bitArrays at the end of the script? Surely since they're local they'll be discarded once that function ends?
Also any reason why you declare the bitarrays explicitly empty beforehand, instead of just doing:
Cheers
got a bug today with array that where not initialized at the beginning. they just memory garbage from an other variable that wasnt cleared at end.