How do I get Rhino 7 to turn the points on a polyline into (x,y,z) coordinates that I can export into Excel? It used to be easy in Rhino 5?
Try this python script:
#! python 3
import rhinoscriptsyntax as rs
from System.Windows import Forms
import os
def polyline_filter(obj, geo, ci):
return rs.IsPolyline(obj)
def get_save_path(name=""):
dialog = Forms.SaveFileDialog()
doc_path = rs.DocumentPath()
if doc_path is not None:
local_path = '\\'.join(doc_path.split('\\')[:-1])
dialog.InitialDirectory = local_path
dialog.DefaultExt = "csv"
dialog.Filter = "csv files (*.csv)|*.csv|All files (*.*)|*.*"
dialog.RestoreDirectory = True
dialog.Title = "Save"
dialog.FileName = name
return dialog.FileName if dialog.ShowDialog() == Forms.DialogResult.OK else None
def write_csv(full_path, data):
with open(full_path, 'w') as file:
for line in data:
file.write(','.join([str(x) for x in line]) + '\n')
def export_polyline_points():
polyline = rs.GetObject("Select polyline to export", filter=rs.filter.curve, custom_filter=polyline_filter, preselect=True)
if not polyline:
print("Cancel")
return
verts = rs.PolylineVertices(polyline)
data = [[v.X, v.Y, v.Z] for v in verts]
full_path = get_save_path("polyline points")
if full_path is None:
print("Cancel")
return
write_csv(full_path, data)
print("Successfully created {}".format(full_path))
os.startfile(full_path)
if __name__ == "__main__":
export_polyline_points()
use ExtractPt and export selected, export as .csv or points .txt which will export it as csv either.
