Skip to content

Commit

Permalink
Added CenterMark.rvb
Browse files Browse the repository at this point in the history
  • Loading branch information
dalefugier committed Oct 14, 2013
1 parent 359b24f commit 27771bd
Showing 1 changed file with 158 additions and 0 deletions.
158 changes: 158 additions & 0 deletions CenterMark.rvb
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 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, 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 circle to add center mark", RH_CRV)
If IsNull(strCurve) Then Exit Sub

' Is it really a circle?
If Not Rhino.IsCircle(strCurve) Then
Call Rhino.Print("Curve it not a 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("Circle 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
arrCenter = Rhino.CircleCenterPoint(strCurve)

' 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, 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 circle to add center line", RH_CRV)
If IsNull(strCurve) Then Exit Sub

' Is it really a circle?
If Not Rhino.IsCircle(strCurve) Then
Call Rhino.Print("Curve it not a 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("Circle 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
arrCenter = Rhino.CircleCenterPoint(strCurve)
dblRadius = Rhino.CircleRadius(strCurve)

' 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

0 comments on commit 27771bd

Please sign in to comment.