Saturday, March 31, 2007

Script

I figured I would post the script I have been working on so that everyone can benefit. Maybe someone could break it down and take it further, or create something more interesting.
Anyway....

Option Explicit
Sub Main
Dim arrObjects, strObject, arrPoints, arrPoint, strPoint
Dim strFileName, strFilter, objFSO, objStream
Dim strPreX, strPreY, strPreZ
Dim strPostX, strPostY, strPostZ
Dim strDelimiter
' User-definable prefixes
strPreX = ""
strPreY = ""
strPreZ = ""
' User-definable postfixes
strPostX = ""
strPostY = ""
strPostZ = ""
' User-definable delimiter(s)
strDelimiter = ","
' User-definable file filters
strFilter = "Excel File (*.xls)*.xlsAll Files (*.*)*.*"
' Get the points to export
Dim strObj : strObj = Rhino.GetObject("Select a curve")
If Rhino.IsCurve(strObj) Then

Dim x : x = 600 arrPoints = Rhino.DivideCurve (strObj, x, vbTrue)
For Each arrPoint In arrPoints
Dim arrPT : arrPT = Rhino.AddPoint (arrPoint)

Next
arrObjects = Rhino.ObjectsByType (1 , vbTrue)
' Get the filename to create
strFileName = Rhino.SaveFileName("Save Point Coordinates As", strFilter)
If IsNull(strFileName) Then Exit Sub
' Get the file system object
Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
' Get a new text file
Set objStream = objFSO.CreateTextFile(strFileName, True)
If Err Then
MsgBox Err.Description
Exit Sub
End If
For Each strObject In arrObjects
Dim k

k = k + 1
Dim arrPTcord : arrPTcord = Rhino.PointCoordinates (strObject)
Dim dblParam : dblParam = Rhino.CurveClosestPoint(strObj, arrPTcord)
Dim arrData : arrData = Rhino.CurveCurvature (strObj, dblParam)

strPoint = CStr(arrData(3))
' Write the coordinate to the file
objStream.WriteLine(strPoint)
Next
End If
objStream.Close

End Sub

Main

-Skylar

No comments: