forked from mcneel/MOVED-rhinoscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExportBoundingBox.rvb
84 lines (64 loc) · 2.35 KB
/
ExportBoundingBox.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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ExportBoundingBox.rvb -- August 2011
' 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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ExportBoundingBox
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ExportBoundingBox
' Local constants
Const FILESPEC = "Comma-Separated Value File (*.csv)|*.csv||"
' Local variables
Dim arrObjects, strObject, strFileName
Dim objFSO, objStream, strLine
Dim nPrecision
' Get the objects to export
arrObjects = Rhino.GetObjects("Select objects", 0, True, True)
If IsNull(arrObjects) Then Exit Sub
' Get the filename to create
strFileName = Rhino.SaveFileName("Save As", FILESPEC)
If IsNull(strFileName) Then Exit Sub
' Get the file system object
Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
' Create a new text file
Set objStream = objFSO.CreateTextFile(strFileName, True)
If Err Then
MsgBox Err.Description
Exit Sub
End If
' Used for formatting point strings
nPrecision = Rhino.UnitDistanceDisplayPrecision
' Process each selected object
For Each strObject In arrObjects
strLine = FormatBoundingBox(strObject, nPrecision)
objStream.WriteLine(strLine)
Next
' Close the file
objStream.Close
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' FormatBoundingBox
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function FormatBoundingBox(ByVal strObject, ByVal nPrecision)
' Local variables
Dim strName, strLayer, arrBox, arrPoint, strLine
' Get the object's bounding box
arrBox = Rhino.BoundingBox(strObject)
' Get the object's user-defined name
strName = Rhino.ObjectName(strObject)
If IsNull(strName) Then strName = "<none>"
' Get the object's layer
strLayer = Rhino.ObjectLayer(strObject)
' Format a delimtied string
strLine = strObject & "," & strName & "," & strLayer
For Each arrPoint In arrBox
strLine = strLine & ","
strLine = strLine & Rhino.Pt2Str(arrPoint, nPrecision)
Next
' Done
FormatBoundingBox = strLine
End Function