Notifications
Clear all

[Closed] Array-loop problem

Hey, I’m making some tools for selecting things in polyobjects. I have a problem with a tool like below. It adds every other polygon to the selection(or every nth in final) based on the facenumber.

The problem I have is that the index gets out of range if it tries to select polygons after the last facenumber. What can I do to prevent it from getting out of range?

(
rollout mainroll “Select polygons”
(
group “Selection”
(
button Nthsel “Nth Sel”
)
on Nthsel pressed do undo on
(
FaceSel = polyop.getfaceselection $.baseobject
Facearr = polyop.getfaceselection $.baseobject
for i in FaceSel do
append Facearr (i+2)
setfaceselection $ Facearr
redrawviews()
)
)
main = newrolloutfloater “Nth Select” 130 120
addrollout mainroll main
)

Help?

CML

1 Reply

Woohoo I solved it, I’m soo proud:)
Did it like so:
FaceSel = polyop.getfaceselection $.baseobject
Facearr = polyop.getfaceselection $.baseobject
for i in FaceSel do
[color=mediumturquoise]if[/color] i < ($.faces.count-1) [size=2][color=mediumturquoise]then
[/color][/size]append Facearr (i+2)
setfaceselection $ Facearr
redrawviews()

(Remember I’m newb so this is a big triumph for me:) )

CML