forked from mcneel/MOVED-rhinoscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CenterMark.rvb
175 lines (143 loc) · 5.63 KB
/
CenterMark.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' CenterMark.rvb -- October 2013
' If this code works, it was written by Dale Fugier.
' If not, I don't know who wrote it.
' Works with Rhinoceros 5.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Draws a center mark
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub CenterMark
' Local constants
Const RH_CRV = &h4
' Local variables
Dim strCurve, arrPlane, blnIsCircle, dblSize
Dim arrCenter, arrDir, arrStart, arrEnd
Dim arrLines(1)
' Hey, only Rhinoceros 5...
If (Rhino.ExeVersion < 5) Then
Call Rhino.Print("This script requires Rhinoceros 5 or greater.")
Exit Sub
End If
' Select a circle
strCurve = Rhino.GetObject("Select an arc or circle to add center mark", RH_CRV)
If IsNull(strCurve) Then Exit Sub
' Is it really a circle?
If Rhino.IsCircle(strCurve) Then
blnIsCircle = True
ElseIf Rhino.IsArc(strCurve) Then
blnIsCircle = False
Else
Call Rhino.Print("Curve is not an arc or circle.")
Exit Sub
End If
' Is the circle planar to the active construction plane?
arrPlane = Rhino.ViewCPlane
If Not Rhino.IsCurveInPlane(strCurve, arrPlane) Then
Call Rhino.Print("Curve does not lie on the active construction plane.")
Exit Sub
End If
Call Rhino.EnableRedraw(False)
' Get the center mark size of the current dimension style
dblSize = Rhino.DimStyleCentermarkSize(Rhino.CurrentDimStyle)
' Get the center point of the circle
If blnIsCircle Then
arrCenter = Rhino.CircleCenterPoint(strCurve)
Else
arrCenter = Rhino.ArcCenterPoint(strCurve)
End If
' Create a center mark line in the x-axis direction
arrDir = Rhino.VectorScale(arrPlane(1), dblSize)
arrStart = Rhino.PointSubtract(arrCenter, arrDir)
arrEnd = Rhino.PointAdd(arrCenter, arrDir)
arrLines(0) = Rhino.AddLine(arrStart, arrEnd)
' Create a center mark line in the y-axis direction
arrDir = Rhino.VectorScale(arrPlane(2), dblSize)
arrStart = Rhino.PointSubtract(arrCenter, arrDir)
arrEnd = Rhino.PointAdd(arrCenter, arrDir)
arrLines(1) = Rhino.AddLine(arrStart, arrEnd)
Call Rhino.AddObjectsToGroup(arrLines, Rhino.AddGroup)
Call Rhino.EnableRedraw(True)
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Draws a center line
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub CenterLine
' Local constants
Const RH_CRV = &h4
' Local variables
Dim strCurve, arrPlane, blnIsCircle, dblSize
Dim arrCenter, dblRadius, arrDir, arrStart, arrEnd
Dim arrLines(5)
' Hey, only Rhinoceros 5...
If (Rhino.ExeVersion < 5) Then
Call Rhino.Print("This script requires Rhinoceros 5 or greater.")
Exit Sub
End If
' Select a circle
strCurve = Rhino.GetObject("Select an arc or circle to add center mark", RH_CRV)
If IsNull(strCurve) Then Exit Sub
' Is it really a circle?
If Rhino.IsCircle(strCurve) Then
blnIsCircle = True
ElseIf Rhino.IsArc(strCurve) Then
blnIsCircle = False
Else
Call Rhino.Print("Curve is not an arc or circle.")
Exit Sub
End If
' Is the circle planar to the active construction plane?
arrPlane = Rhino.ViewCPlane
If Not Rhino.IsCurveInPlane(strCurve, arrPlane) Then
Call Rhino.Print("Curve does not lie on the active construction plane.")
Exit Sub
End If
Call Rhino.EnableRedraw(False)
' Get the center mark size of the current dimension style
dblSize = Rhino.DimStyleCentermarkSize(Rhino.CurrentDimStyle)
' Get the center point of the circle
If blnIsCircle Then
arrCenter = Rhino.CircleCenterPoint(strCurve)
dblRadius = Rhino.CircleRadius(strCurve)
Else
arrCenter = Rhino.ArcCenterPoint(strCurve)
dblRadius = Rhino.ArcRadius(strCurve)
End If
' Create center mark line in the x-axis direction
arrDir = Rhino.VectorScale(arrPlane(1), dblSize)
arrStart = Rhino.PointSubtract(arrCenter, arrDir)
arrEnd = Rhino.PointAdd(arrCenter, arrDir)
arrLines(0) = Rhino.AddLine(arrStart, arrEnd)
' Create first extension line in the x-axis direction
arrDir = Rhino.VectorScale(arrPlane(1), dblRadius + dblSize)
arrStart = Rhino.PointSubtract(arrCenter, arrDir)
arrDir = Rhino.VectorScale(arrPlane(1), dblSize + dblSize)
arrEnd = Rhino.PointSubtract(arrCenter, arrDir)
arrLines(1) = Rhino.AddLine(arrStart, arrEnd)
' Create second extension line in the x-axis direction
arrDir = Rhino.VectorScale(arrPlane(1), dblSize + dblSize)
arrStart = Rhino.PointAdd(arrCenter, arrDir)
arrDir = Rhino.VectorScale(arrPlane(1), dblRadius + dblSize)
arrEnd = Rhino.PointAdd(arrCenter, arrDir)
arrLines(2) = Rhino.AddLine(arrStart, arrEnd)
' Create center mark line in the y-axis direction
arrDir = Rhino.VectorScale(arrPlane(2), dblSize)
arrStart = Rhino.PointSubtract(arrCenter, arrDir)
arrEnd = Rhino.PointAdd(arrCenter, arrDir)
arrLines(3) = Rhino.AddLine(arrStart, arrEnd)
' Create first extension line in the y-axis direction
arrDir = Rhino.VectorScale(arrPlane(2), dblRadius + dblSize)
arrStart = Rhino.PointSubtract(arrCenter, arrDir)
arrDir = Rhino.VectorScale(arrPlane(2), dblSize + dblSize)
arrEnd = Rhino.PointSubtract(arrCenter, arrDir)
arrLines(4) = Rhino.AddLine(arrStart, arrEnd)
' Create second extension line in the y-axis direction
arrDir = Rhino.VectorScale(arrPlane(2), dblSize + dblSize)
arrStart = Rhino.PointAdd(arrCenter, arrDir)
arrDir = Rhino.VectorScale(arrPlane(2), dblRadius + dblSize)
arrEnd = Rhino.PointAdd(arrCenter, arrDir)
arrLines(5) = Rhino.AddLine(arrStart, arrEnd)
Call Rhino.AddObjectsToGroup(arrLines, Rhino.AddGroup)
Call Rhino.EnableRedraw(True)
End Sub