Script for exporting control points of multiple curves

Hello,

I need some expert help with a script for exporting the control points of multiple curves. The curves will be planar, one in front of the other along the X-axis (like cross-sections through a cylinder along the X-axis).

There is this script from the wiki mcneel page which I found (original indicated by ** below), but it only exports the control points of a single curve. Basically what I need in the end is a .csv-file with the point coordinates of the control points of multiple curves, sorted in the correct order (i.e. one point after the other along the curves, for each curve, one curve after the other).

I know nothing about scripting so my sorry attempts at modifying it did not get me very far. I managed to have it let me select multiple curves (see modifications indicated by * in script below), but then I always get an error message at the next step after my selecting.

I hope this is a simple thing for someone who is more knowledgeable than me…

Thanks in advance!

Antus

Sub ExportControlPoints()

 **'Pick a curve object**
 **Dim strObject**

 **strObject = Rhino.GetObject("Select curve", 4)**
  *strObject = Rhino.GetObjects("Select curves", 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)**
   **objStream.WriteLine(strText)**
 **Next**

 **' Close the file**
 **objStream.Close**

End Sub

Hi Ben- you’ll need to select multiple curves ( Rhino.GetObjects() ) as an array, and set up another For loop to process the curves one by one, then nested it that, the loop that gets the points for each curve.

Sub Main()
'Pick  objects
Dim aObjects

aObjects = Rhino.GetObjects("Select curves", 4,, True)

If Not IsArray(aObjects) 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	

Dim strObject, arrPoints
For Each strObject In aObjects 'First loop for curves
	' Get the curve's control points
	arrPoints = Rhino.CurvePoints(strObject)
	
	If IsArray(arrPoints) Then 


		' Write each point as text to the file
		Dim strPoint, strText
		For Each strPoint In arrPoints ' Nested loop for points
			strText = Rhino.Pt2Str(strPoint)
			objStream.WriteLine(strText)
		Next
		
	End If

Next		
' Close the file
objStream.Close

End Sub

-Pascal

Hi Pascal,

thanks for the quick reply and the script with the explanations, it works great. The idea behind the script makes perfect sense, at my level of understanding I would not have been able to set it up, though. Must learn this…

All the best

antus