[Closed] scanned twice in a loop :/
I am using a loop like ” for io in selection do()” but I dont want my i object to be scanned twice.
I think there is other loop like “for i=1 in selection do()” but this one doesnt work.
Any idea?
Thx
If you’re not changing the selection, there should be no problem, however it’s better practice not to work on a live selection set and assign the nodes you’re working with to some variable instead.
The second form of for loop in your case would be “for i = 1 to selection.count do ()” but if you don’t really need to work with the indices in the loop, there’s no need for it.
You can do something like this:
arr = selection as array
for i in arr do
(
— CODE HERE
)
or if you want to do the other way around, the corrected version of what you’ve posted is:
for i = 1 to selection.count do
(
—CODE HERE
selection[i].name = “Doh!”
)
I hope this helps!
Edit: Oh just one more thing, none of the above scans the object twice, what might be happening is that you need to enclose all your code in brackets ()
Not sure if it’s faster or not, I could test I suppose, but I think using
for o in selection or something similar is better than using for i = 1 to selection.count ect
I know for things like bitarrays, in the MXS help, it says to not convert/store in an array, but use it as a bitarray, otherwise it will be orders of magnitude slower or something.
Also for bitarrays (vert selection for example), from what I can tell, you cannot access a bit like you would an array value, like array[1]. So for an bitarray, you would use
for vert in VertArray do.
Where vert can be any name you want, and VertArray is a bitarray.