Loop in python

Hello everybody,

I tried to write a simple code in python for grasshopper. I wanted to offset a curve on a surface for several times and I defined the loop like what I mentioned in the first photo. the problem is that instead of offsetting each curve in a row it just duplicate the first curve in itself.
Does anyone know what my problem is?

Hello- it looks like you’ll have to increment the offset every time as well somehow

for k in range(nodiv):
f.append(rs.OffestCurveOnSurface(g, surface, (k+1)*offset)

Something like that.


Hello Pascale,

Thanks for your help. Unfortunately, it didn’t make any changes on the final result. Actually, I have assigned a certain factor to “offset” variable and the code is supposed to duplicate each curve in a row with a certain amount. But what it does is that it just duplicate the first curve with the amount assigned to “nodiv” variable and it doesn’t

offset anything at all.

Hello - ok… post the gh file and I’ll see if I can see what is going on…


offsetcrvonsrf.gh (66.8 KB)

Thank you in advance for helping me, Pascale.

Hello - the output from OffsetCrvOnSrf is a list, so you need to iterate that to add each one to crvList.

This seems to work:

for i in range(nodiv):

    if f:
        for crv in f:

curves = crvlist


1 Like