Files
Create acute angular dimension
Code
Module: mMain
'Demonstrates how to create an acute angle dimension between two _
intersecting sketch lines. The macro works by finding which _
end point on each line is the furthest from the intersection _
point and then placing the angular dimension at the halfway _
point between those two far points.
'Precondition: sketch is active and two sketch lines are selected.
'Written by Artem Taturevych (https://forum.solidworks.com/message/325514)
'Modified by Keith Rice
'CADSharp LLC
'www.cadsharp.com
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swSkSeg As SldWorks.SketchSegment
Dim swSkLine(1) As SldWorks.SketchLine
Dim swCurve(1) As SldWorks.Curve
Dim swEndPts(1) As SldWorks.SketchPoint
Dim swSkPoint(1) As SldWorks.SketchPoint
Dim dblDistance(1) As Double
Dim vIntersectPt As Variant
Dim i As Integer, j As Integer
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
For i = 0 To 1
Set swSkLine(i) = swSelMgr.GetSelectedObject6(i + 1, -1)
Set swSkSeg = swSkLine(i)
Set swCurve(i) = swSkSeg.GetCurve
Next
vIntersectPt = swCurve(0).IntersectCurve(swCurve(1), Array(0, 0, 0), Array(0, 0, 0), Array(0, 0, 0), Array(0, 0, 0))
For i = 0 To 1
Set swEndPts(0) = swSkLine(i).GetStartPoint2
Set swEndPts(1) = swSkLine(i).GetEndPoint2
For j = 0 To 1
dblDistance(j) = Sqr((swEndPts(j).X - vIntersectPt(0)) ^ 2 + _
(swEndPts(j).Y - vIntersectPt(1)) ^ 2 + _
(swEndPts(j).Z - vIntersectPt(2)) ^ 2)
Next
If dblDistance(0) > dblDistance(1) Then
Set swSkPoint(i) = swSkLine(i).GetStartPoint2
Else
Set swSkPoint(i) = swSkLine(i).GetEndPoint2
End If
Next
swSkLine(0).Select4 False, Nothing
swSkLine(1).Select4 True, Nothing
swApp.SetUserPreferenceToggle _
swUserPreferenceToggle_e.swInputDimValOnCreate, False
swModel.AddDimension2 (swSkPoint(0).X + swSkPoint(1).X) / 2, _
(swSkPoint(0).Y + swSkPoint(1).Y) / 2, _
(swSkPoint(0).Z + swSkPoint(1).Z) / 2
swApp.SetUserPreferenceToggle _
swUserPreferenceToggle_e.swInputDimValOnCreate, True
End Sub