forked from mcneel/rhino-developer-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExportNamedPoints.rvb
117 lines (96 loc) · 3.32 KB
/
ExportNamedPoints.rvb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ExportNamedPoints.rvb -- October 2005
' If this code works, it was written by Dale Fugier.
' If not, I don't know who wrote it.
' Works with Rhino 4.0.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
' Declare global variables
Dim g_nCounter
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Subroutine: CreateNamedPoints
' Purpose: Creates points with sequential object names.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub CreateNamedPoints
' Declare variables
Dim arrPoints
Dim strMessage, strObject
Dim i
' Initialize global counter, if necessary
If IsNull(g_nCounter) Then
g_nCounter = g_nCounter + 1
End If
' Create points
strMessage = "Location of point object"
arrPoints = Rhino.GetPoints(False, False, strMessage, strMessage)
If IsArray(arrPoints) Then
For i = 0 To UBound(arrPoints)
strObject = Rhino.AddPoint(arrPoints(i))
If Not IsNull(strObject) Then
g_nCounter = g_nCounter + 1
Rhino.ObjectName strObject, CStr(g_nCounter)
End If
Next
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Subroutine: ExportNamedPoints
' Purpose: Export points, sorted by object name, to a text file.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ExportNamedPoints
' Declare constants
Const rhPoint = 1
' Declare variables
Dim arrObjects, arrNames, arrSorted, arrPoint
Dim strObject, strName, strFilter, strFileName
Dim objFSO, objStream
Dim i
' Select points objects to export
arrObjects = Rhino.GetObjects("Select points to export", rhPoint, True, True)
If Not IsArray(arrObjects) Then Exit Sub
' Define array of object names
ReDim arrNames(UBound(arrObjects))
' Build array of object names
For i = 0 To UBound(arrObjects)
strName = Rhino.ObjectName(arrObjects(i))
If IsNull(strName) Then
MsgBox "Selected point object is unnamed."
Exit Sub
Else
arrNames(i) = strName
End If
Next
' Sort the array of object names
arrSorted = Rhino.Sort(arrNames)
If Not IsArray(arrSorted) Then Exit Sub
' Prompt the user to specify a file name
strFilter = "Text File (*.txt)|*.txt|All Files (*.*)|*.*||"
strFileName = Rhino.SaveFileName("Save Point Coordinates As", strFilter)
If IsNull(strFileName) Then Exit Sub
' Get the file system object
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
' For each object name in the sorted array,
' find all of the objects that have that name
' and export their point coordinates
For Each strName In arrSorted
arrObjects = Rhino.ObjectsByName(strName)
If IsArray(arrObjects) Then
For Each strObject In arrObjects
' Export the point coordintes vertices
arrPoint = Rhino.PointCoordinates(strObject)
If IsArray(arrPoint) Then
objStream.WriteLine Rhino.Pt2Str(arrPoint)
End If
Next
End If
Next
' Close the file
objStream.Close
End Sub