Site Tools

Export Curve Control Points

Developer: RhinoScript
Summary: How to export the 3D coordinates of a curve's control points to a text file.


The following code sample demonstrates how to select a curve object and export the 3D coordinates of its control points to a text file.

   Sub ExportControlPoints()
     'Pick a curve object
     Dim strObject
     strObject = Rhino.GetObject("Select curve", 4)
     If IsNull(strObject) Then Exit Sub
     ' Get the curve's control points
     Dim arrPoints
     arrPoints = Rhino.CurvePoints(strObject)
     If Not IsArray(arrPoints) 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 Each strPoint In arrPoints
       strText = Rhino.Pt2Str(strPoint)
     ' Close the file
   End Sub

developer/scriptsamples/exportcontrolpoints.txt ยท Last modified: 2020/08/14 (external edit)