forked from mcneel/MOVED-rhinoscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExportPoints.rvb
82 lines (68 loc) · 2.59 KB
/
ExportPoints.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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ExportPoints.rvb -- May 2012
' 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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Subroutine: ExportPoints
' Purpose: Export points and point clouds to a text file.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ExportPoints
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 = "Text File (*.txt)|*.txt|All Files (*.*)|*.*||"
' Get the points to export
arrObjects = Rhino.GetObjects("Select points", 3, True, True)
If IsNull(arrObjects) Then Exit Sub
' 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")
' Get a new text file
On Error Resume Next
Set objStream = objFSO.CreateTextFile(strFileName, True)
If Err Then
MsgBox Err.Description
Exit Sub
End If
' Process point clouds
For Each strObject In arrObjects
If Rhino.IsPointCloud(strObject) Then
arrPoints = Rhino.PointCloudPoints(strObject)
If IsArray(arrPoints) Then
For Each arrPoint In ArrPoints
strPoint = strPreX & CStr(arrPoint(0)) & strPostX & strDelimiter & strPreY & CStr(arrPoint(1)) & strPostY & strDelimiter & strPreZ & CStr(arrPoint(2)) & strPostZ
' Write the coordinate to the file
objStream.WriteLine(strPoint)
Next
End If
' Process point clouds
ElseIf Rhino.IsPoint(strObject) Then
arrPoint = Rhino.PointCoordinates(strObject)
If IsArray(arrPoint) Then
strPoint = strPreX & CStr(arrPoint(0)) & strPostX & strDelimiter & strPreY & CStr(arrPoint(1)) & strPostY & strDelimiter & strPreZ & CStr(arrPoint(2)) & strPostZ
' Write the coordinate to the file
objStream.WriteLine(strPoint)
End If
End If
Next
' Write the file
objStream.Close
End Sub