forked from mcneel/MOVED-rhinoscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DumpArrayInfo.rvb
106 lines (96 loc) · 2.92 KB
/
DumpArrayInfo.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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' DumpArrayInfo.rvb -- October 2007
' 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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Prints an array to the command line
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub DumpArrayInfo(arr)
Dim i, j, d, b
If IsArray(arr) Then
For i = 0 To UBound(arr)
If IsArray(arr(i)) Then
d = GetArrayDim(arr(i))
If IsNull(d) Then
Rhino.Print "Element(" & CStr(i) & ") is not dimensioned"
Else
Rhino.Print "Element(" & CStr(i) & ") dimension = " & CStr(d)
For j = 1 To d
b = GetArrayUBound(arr(i), j)
If IsNull(b) Then
Rhino.Print " Dimension(" & CStr(j) & ") has no bounds"
Else
Rhino.Print " Dimension(" & CStr(j) & ") bounds = " & CStr(b)
End If
Next
End If
Else
Rhino.Print "Element(" & CStr(i) & ") is not an array"
End If
Next
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Description
' Returns the dimension of an array.
'Parameters
' arr - Name of the array variable.
'Returns
' The dimension of the array if successful.
' Null on error.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function GetArrayDim(ByVal arr)
GetArrayDim = Null
Dim i
If IsArray(arr) Then
For i = 1 To 60
On Error Resume Next
UBound arr, i
If Err.Number <> 0 Then
GetArrayDim = i-1
Exit Function
End If
Next
GetArrayDim = i
End If
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Description
' Safely returns the largest available subscript for
' the indicated dimension of an array.
'Parameters
' arr - Name of the array variable.
' i - Number indicating which dimension's upper bound to return.
'Returns
' The upper bounds for the indicated dimension if successful.
' Null on error.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function GetArrayUBound(ByVal arr, ByVal i)
GetArrayUBound = Null
If IsArray(arr) Then
On Error Resume Next
b = UBound(arr, i)
If Err.Number = 0 Then GetArrayUBound = b
End If
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Tester
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub TestDumpArrayInfo
Dim arr0(6)
Dim arr1(5,4)
Dim arr2(3,2,1)
Dim arr3()
Dim arr4
Dim arr(4)
arr(0) = arr0
arr(1) = arr1
arr(2) = arr2
arr(3) = arr3
arr(4) = arr4
DumpArrayInfo arr
End Sub
TestDumpArrayInfo