Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

Python Rhino.Geometry Line list from script

$
0
0

@esolomon1221 wrote:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
import csv

a = [] # new. correct because global scope
def CSVlist():
    sc.doc = Rhino.RhinoDoc.ActiveDoc
    #prompt the user for a file to import
    filter = "CSV file (*.csv)|*.csv|*.txt|All Files (*.*)|*.*||"
    filename = rs.OpenFileName("Open Point File", filter)
    if not filename: return

    with open(filename) as csvfile:
        reader = csv.reader(csvfile)
        #a = [] # wrong because function scope
        for row in reader:

            p1 = Rhino.Geometry.Point3d(float(row[0]),
                                        float(row[1]),
                                        0)
            p2 = Rhino.Geometry.Point3d(float(row[2]),
                                        float(row[3]),
                                        0)
            """
            p1 = rs.AddPoint(float(row[0]),
                             float(row[1]),
                             0)
            p2 = rs.AddPoint(float(row[2]),
                             float(row[3]),
                             0)
            """
            x = Rhino.Geometry.Line(p1,p2)
            print(x)
            a.append(x)
            #print(rs.AddLine(p1,p2))
            #a.append(rs.AddLine(p1,p2))

########################################################

I am creating a list of lines and points from text. I want to output directly to line because it is easier than managing the creation of a polyline. I can output as a text fine with start points and end points of line segments, but the conversion from text to line is invalid. What to do?

text_to_line
##################

# Check to see if this file is being executed as the "main" python
# script instead of being used as a module by some other python script
# This allows us to use the module which ever way we want.
if( __name__ == "__main__" ):
    if x:
        CSVlist()

Edit: I have attached the Label and/or Line components to a parameter, for which the representation is null.

Edit2: Solved by bringing a to global scope

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles