RhinoScript exporting points to processing
From KokkugiaWiki
importing points to processing
The following code imports a txt file of points and builds either ellipses or vectors (you will need the kGeom libraries) to use the kVec data type.
ellipse
size(500,500);
String points[] = loadStrings("pointFromRhino.txt");
for (int i=0; i < points.length; i++) {
String list[] = split(points[i], ',');
ellipse(float(list[0]), float(list[1]),5,5);
}
vectors
size(500,500);
String points[] = loadStrings("pointFromRhino.txt");
for (int i=0; i < points.length; i++) {
String list[] = split(points[i], ',');
new kVec(float(list[0]), float(list[1]), float(list[2]));
}
exporting points from rhino
Call ExportControlPoints
Sub ExportControlPoints
'Pick a curve object
Dim arrPoints
arrPoints = Rhino.GetObjects("Select points", 0)
If IsNull(strObject) Then Exit Sub
' Prompt the user to specify a file name
Dim strFilter, strFileName
strFilter = "Text File (*.txt)|*.txt|All Files (*.*)|*.*||"
strFileName = Rhino.SaveFileName("Save Control Points As", strFilter)
If IsNull(strFileName) Then Exit Sub
' Get the file system object
Dim objFSO, objStream
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Open a text file to write to
On Error Resume Next
Set objStream = objFSO.CreateTextFile(strFileName, True)
If Err Then
MsgBox Err.Description
Exit Sub
End If
' Write each point as text to the file
Dim strPoint, strText
For i=0 To UBound(arrPoints)
Rhino.Print i
strPoint = Rhino.PointCoordinates(arrPoints(i))
strText = Rhino.Pt2Str(strPoint)
objStream.WriteLine(strText)
Next
' Close the file
objStream.Close
End Sub
