How to import CSV file to Rhino using Python and connect the points using interpCRV command

1.4k views Asked by At

I have a program that interpolates between different predefined geometries and outputs a CSV file with points defined by X Y Z columns. For instance:

1,5,0.2

3,4,0.2

1,5,0.3

3,4,0.3

I am trying to import that file into Rhino, and have any points with a common Z value connect by a _interpCRV In the order they are imported The end result is that I'll have similar shapes (like a circle) at different Z values. I will have to manipulate the geometry further after that, but I am having difficulty getting this first step started. Thanks in advance!

1

There are 1 answers

0
user2232395 On

you can import point from txt with this:

def ReadPointsDef(filename):

if not filename: return

#read each line from the file
file = open(filename, "r")
#list of lines
contents = file.readlines()
#contents = [line.rstrip('\n') for line in file]
file.close()

# points=[]
points3d = Rhino.Collections.Point3dList()
for text in contents:
    items = text.strip("()\n").split(",")    
    if len(items)==3:
        x = float(items[0])
        y = float(items[1])
        z = float(items[2])
        points3d.Add(x,y,z)

#contents = [__point_from_string(line) for line in contents]
#return points
return points3d

Then use wherever you want, like this sample:

points = ReadPointsDef("C:/Users/UsuarioStd/Documents/points.txt")
interCurve = rs.AddInterpCurve(points,3,4) 
rs.ObjectColor(interCurve, [255,0,0])#rojo

You must to group by Z and use the groups to build your curves. Yor must to give more information about the output taht you want, a graph would be good. Greetings