2

I wrote my first lines (with the help of SO):

import rhinoscriptsyntax as rs

obj = rs.GetObject("Select a curve", rs.filter.curve)
maxd = input("max offset: ")
a = input("first offset: ")
b = input("next offset: ")


if rs.IsCurve(obj):
    i=0
    while i < maxd:
        rs.OffsetCurve( obj, [0,0,0], -i )
        i += a
        rs.OffsetCurve( obj, [0,0,0], -i )
        i += b

Now I've tried to take it further by inserting a list for the offset inputs. But it seems I get an infinite loop at the end. Also, the first rs.OffsetCurve() seems to run twice or i is not updated with the first run of the second rs.OffserCurve() while loop.

import rhinoscriptsyntax as rs

obj = rs.GetObject("Select a curve", rs.filter.curve)
maxd = input("max offset: ")
a = input("first offset: ")

offlist = []

while True:
    b = input("next offset or 0 for exit: ")
    offlist.append(b)
    if b == 0:
        break

if rs.IsCurve(obj):
    i=0
    while i < maxd:
        rs.OffsetCurve( obj, [0,0,0], -i )
        i = a
        c = len(offlist)
        k = 0
        while k != c:
            rs.OffsetCurve( obj, [0,0,0], -i )
            i = offlist[k]
            k += 1
Trevor Reid
  • 3,310
  • 4
  • 27
  • 46

2 Answers2

2

while i < maxd: along with i = a at each step of the cycle and not changing maxd nor a at both cycles at all may cause this behavior.

Btw, I'd consider naming your variables in such way that you or any other dev could understand what's going on here just with a single look. Also, you can consider whether it is a good idea to use nested while loops in this case.

Trevor Reid
  • 3,310
  • 4
  • 27
  • 46
d2718nis
  • 1,279
  • 9
  • 13
0

You are forgetting to update the value of the variable a and in consequence, the counter i of the outer while loop. What I usually do is follow manually the values of each the counters inside the loops for a few iterations to debug my code.

Amani
  • 119
  • 2
  • 13