Maxscript for loop hopping


Can anyone help with speeding up a for loop iteration through UV faces in maxscript without going through every single face?

I want to check if there are faces that are isolated and not part of an element and basically skip the element and thereby avoid having to loop through all the remaining faces in the element. I tried using a for loop with the index in reverse with the “by” value set by the numberset found from each element thereby leap frogging through the faces to the next element. If there are any single faces found then it saves them to an array inside the loop. The actual “leapfrogging” counter from the number set works and speeds everything up but the final single face array is not what I want I think due to the difference created by indexing rather than finding the face IDs I may be wrong? In semi psudo code its like this:

Counter = -1
For uvFace in uvFaces by counter do
Select uvFace
Get element from uvFace
Get number of faces from element
If number of faces ==1 save uvFace to array
Counter = number of faces

Any help would be very much appreciated.
Kind regards…


just substract element face indexes from all indexes bitarray

mapfaces = #{1..mapFacesCount}
isolated_mapfaces = for i in mapfaces where mapfaces[i] collect
    elem = get_element_faces obj i -- returns bitarray
    mapfaces -= elem
    if elem.numberset == 1 then i else dontCollect


Thank you so much serejah.
I will try this when back at
My desk. Thanks again.


thanks serejah that works great. Am I correct in thinking that collect only returns a normal array and not a bit array?


yes, it creates an array of integers, but you can cast it to bitarray

bits = ( for i=1 to 6 where mod i 2 == 0 collect i ) as BitArray
>> #{2,4,6}


thanks for your help with this.