[Closed] 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}
Hi, could you tell me the logic behind “where mapfaces[i]” is in the first example you showed? Does it mean “where true” seeing how its refering to a bit array? Many thanks.
Yes, while and where expects boolean
I doubt that I could explain it better than mxs reference
it depends on what you mean by valid. Will it work? Yes. Is there any logic in it? No.
Imagine a situation when i is equals to 10 and
elem = get_element_faces obj i
returns bitarray of #{ 10…128 }
you were looking for a single-face-elements and it means that you no longer need to check any mapface of this element (because all of them will return #{10…128}). So you have to somehow skip all those mapfaces.
so you substract all the range from mapfaces
and then when loop proceeds to the next iteration … where mapfaces[i] check happens, but at this time mapfaces[i] is equal to false so this iteration is skipped… and so on to the i == 129
That makes sense to me now. Its a nice dynamic way to control the loop. Many thanks for your help.