Get and Set Dimension Extension Lines Gaps (VBA)
This example shows how to get and set the gaps for the extension lines
of a display dimension.
'-------------------------
' Preconditions: Drawing document is open.
' Drawing
View1 contains a model.
' Edge
on that model is selected.
'
' Postconditions: The value of the selected edge's dimension's
line
' extension
gaps are modified to the specified
' value.
'-------------------------
Option Explicit
Dim swApp As
SldWorks.SldWorks
Dim swModel As
SldWorks.ModelDoc2
Dim swModelDocExt As
SldWorks.ModelDocExtension
Dim swSelMgr As
SldWorks.SelectionMgr
Dim swDrawing As
SldWorks.DrawingDoc
Dim swDisplayDim As
SldWorks.DisplayDimension
Dim boolstatus As
Boolean
Dim longstatus As
Long, longwarnings As Long
Dim UseDoc As
Boolean
Dim retBool As
Boolean
Dim Gap As
Double
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swDrawing = swModel
' Make Drawing View1 active
boolstatus = swDrawing.ActivateView("Drawing
View1")
' Programmatically add a dimension to the selected edge
Set swDisplayDim = swModel.AddDimension2(0.07991695284535,
0.1237274983129, 0)
Debug.Print "Dimension Extension Lines"
Debug.Print ""
' Get document default value for extension lines' gaps
Debug.Print "Value of document default gap: "
& swModel.GetUserPreferenceDoubleValue(swDetailingWitnessLineGap)
Debug.Print " "
' Get a dimension's extension line's gap
retBool = swDisplayDim.GetWitnessLineGap(1,
UseDoc, Gap)
Debug.Print "Get Gap Operation:"
Debug.Print " Use
document default for gap: " & UseDoc
Debug.Print " Gap
value in system units: "
& Gap
Debug.Print " "
' Set the dimension's extension line's gaps
Gap = 0.005
retBool = swDisplayDim.SetWitnessLineGap(0,
False, Gap)
retBool = swDisplayDim.SetWitnessLineGap(1,
False, Gap)
Debug.Print "Set Gap Operation: "
Debug.Print " Gap
value in system units: "
& Gap
Debug.Print " "
' Get the dimension's extension gap again
retBool = swDisplayDim.GetWitnessLineGap(1,
UseDoc, Gap)
Debug.Print "Get Gap Operation:"
Debug.Print " Use
document default for gap: " & UseDoc
Debug.Print " Gap
value in system units: "
& Gap
Debug.Print " "
swModel.GraphicsRedraw
End Sub