Code doesn't work in a while loop but works otherwise

gh.gh (30.6 KB)

I want to be able to after the first set of actions to loop another set. The second set can work if I don’t put it in a while loop, not sure why it fails in a while loop ><

Hi @aeaechan96,

I’m not sure if I am understanding your problem correctly, but in the code as you posted it the while loop is ok on its first pass but failing on its second pass because in that case

srfsInt = rg.Intersect.Intersection.SurfaceSurface(slyce,srf,0)  

is not finding an intersection, so crvz is empty.

When you have to find a problem like this, look at the line no. where the code is failing and start stuffing print statements in to display more and more variables that might be relevant until you find the problem, like so:

print "LenPs", len(Ps), " ptc ", ptc
while len(Ps) < ptc:
    t0 = start.ClosestPoint(sPt, 0)
    vInit = start.TangentAt(t0[-1])
    v0 = rs.VectorRotate(vInit, 0, [0,0,1])
    l0 = rg.Line(sPt, v0, leng)
    nPt = l0.To
    nP0 = srf.ClosestPoint(nPt)
    unPt = nP0[1]
    vnPt = nP0[-1]
    sPn = srf.PointAt(unPt, vnPt)
    Ps.append(sPn)
    mvt = rg.Transform.Translation(rg.Vector3d(sPn) - rg.Vector3d(frm))
    slyce.Transform(mvt)
    srfsInt = rg.Intersect.Intersection.SurfaceSurface(slyce,srf,0)
    print "srfsInt ", srfsInt
    crvz = srfsInt[1]
    print "crvz ", crvz
    print "len crvz " + str(len(crvz))
    crf = crvz[0]
    t = crf.ClosestPoint(sPn,0)
    v = crf.TangentAt(t[-1])
    l = rg.Line(sPn, v, leng)
    nPn = l.To
    nPn0 = srf.ClosestPoint(nPn)
    unPn = nPn0[1]
    vnPn = nPn0[-1]
    sPn = srf.PointAt(unPn, vnPn)
    Ps.append(sPn)
    print "new LenPs ", len(Ps) 

Hope that helps
Jeremy