This is a script that someone kindly provided an outline for me and I have have cleaned up—that still needs work. The objective of the script is to import a CSV file containing layer names. It is supposed to read the file. If it finds a string, it is to create a new layer below the current layer. If finds a value, it is to add a point in the last created layer.
The problem is that the script creates new layers in a mixture of locations. It seems to create some layers below the current layer and some layers at the root.
Why would that be?
I think I have a lack of understanding on how layers work the python interface. The CurrentLayer() function returns a string. How can I distinguish between "Abc"s with a layer structure like this:
Layer 1 Abc Layer 2 Abc
import Rhino import csv import rhinoscriptsyntax as rs import random def importtolayers(): file = rs.OpenFileName(filter = "CSV files|*.csv|Text files|*.txt||", extension = ".csv") with open(file, "rU") as f: reader = csv.reader (f, dialect=csv.excel) parentlayer = rs.CurrentLayer () layer = parentlayer print "Root Layer: ", parentlayer for line in reader: value = line.strip () ; try: if value <> "": float (value) x = rs.AddPoint(rs.Str2Pt(line)) if x: rs.ObjectLayer(x, layer) except ValueError: print "New Layer ", value ; color = rs.CreateColor (random.randint (0, 255), random.randint (0, 255), random.randint (0, 255)) layer = rs.AddLayer(value, color=color, parent=parentlayer) importtolayers()