Curves through points from a point matrix

Hi all,

I’m very new to Python in Rhino and have run into a bit of a snag for a script I’m trying to write. In the lines below, I establish a point matrix based on user input via rs.GetInteger, save those to a list (ptList_1) and then try to create a series of individual curves from rows of x or y points so that I can loft a surface from them. The way it is written now, I can get a curve extending through the entire list, but am not sure how to stop it at each new line so that they’re individual. Sorry if this is poorly explained, but any help would be greatly appreciated!

import rhinoscriptsyntax as rs
import random

# Empty lists
ptList_1 = []

ptList_2 = []
# For curves to loft surface
crvList_1 = []
# For first set of circles
crvList_2 = []
# For second set of circles
crvList_3 = []
# Point dictionary for first matrix set
ptDict_1 = {}
# Point dictionary for second matrix set (moved points)
ptDict_2 = {}

# i, j and k values

imax = rs.GetInteger('Choose an x value', 10)
jmax = rs.GetInteger('Choose a y value', 10)
kmax = rs.GetInteger('Choose a z value', 2)

attPt_1 = rs.AddPoint(random.randrange(1,(imax*5)), random.randrange(1,(jmax*5)), random.randrange(1,30))
#attPt_2 = rs.AddPoint((random.randrange(1,15)*(imax/4)),(random.randrange(1,15)*(imax/4)),(random.randrange(1,15)*(imax/4)))

# Values for first point matrix loop

for i in range(imax):
    for j in range(jmax):
        x = i * 5
        y = j * 5
        point = (x,y,0)
        # Save points to dictionary for line construction
        ptDict_1[(i,j)] = point        
        #print ptList_1

for i in range(imax*jmax):
    distance = rs.Distance(ptList_1[i], attPt_1)
    move_1 = distance/2
    #print move_1
    ptList_2.append(rs.MoveObject(ptList_1[i], (0,0,move_1)))

for j in range(jmax):
        crvList_1.append(rs.AddCurve((ptList_1), 2))

Welcome @jcraig0611,

Are you looking for something akin to this?

import rhinoscriptsyntax as rs
import random

crv_list = [] # stores the curves to loft

imax = rs.GetInteger('Choose an x value', 10)
jmax = rs.GetInteger('Choose a y value', 10)
kmax = rs.GetInteger('Choose a z value', 2)

att_pt = rs.AddPoint(random.randrange(1,(imax*5)), random.randrange(1,(jmax*5)), random.randrange(1,30))

for i in xrange(imax):
    crv_pts = [] # stores all points in x-direction
    for j in xrange(jmax):
        pt = [i*5.0, j*5.0, 0.0]
        dist = rs.Distance(pt, att_pt)
        pt[2] = dist * 0.5 # change z-value

    crv_list.append(rs.AddCurve(crv_pts, 3))

rs.AddLoftSrf(crv_list) # loft curves

rs.DeleteObjects(crv_list) # delete curves from document
#rs.DeleteObject(att_pt) # delete attractor point from document

I’m not exactly sure if I understood you correctly! Let me know.

Yes, this is exactly it! It’s funny how much simpler your code is than my original attempt. I expect mine will get shorter/simpler with time and experience.

Thanks very much for the help! I’m going to compare the two versions to see what I can do better/simpler.

1 Like