Creates a list of data lines from a GHTree of Points where each data line includes:
CurveID, X coordinate, and Z coordinate.
Optionally writes the list to a CSV file if writeCSV is True.
pts - GHTree of Points (DataTree or nested list)
csvPath - full file path for the output CSV file (string, optional)
writeCSV - boolean flag to trigger CSV writing (True/False)
a - List of data lines (each a list: [CurveID, X, Z])
b - Message indicating CSV writing status
# Create a list of data lines starting with a header row
dataLines.append(["CurveID", "X", "Z"])
# Process the GHTree (try as a DataTree; if not, treat as a nested list)
branch = pts.get_Branch(path)
curveID = str(path) # Using the branch path as CurveID
dataLines.append([curveID, pt.X, pt.Z])
for i, branch in enumerate(pts):
curveID = str(i) # Use branch index as CurveID if pts is a nested list
dataLines.append([curveID, pt.X, pt.Z])
# Optionally write the CSV if writeCSV is True and a file path is provided
# Use different file modes based on Python version
if sys.version_info.major >= 3:
# Python 3: open in text mode with newline=""
with open(csvPath, "w", newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerows(dataLines)
# Python 2: open in binary mode
with open(csvPath, "wb") as csvfile:
writer = csv.writer(csvfile)
writer.writerows(dataLines)
msg = "CSV file created at: " + csvPath
msg = "Error writing CSV: " + str(e)