Get Dimension Tolerance Example (VBA)
This example shows how to get dimension tolerance values.
'---------------------------------------------
'
' Preconditions: Model document is open
' and
a dimension is selected.
'
' Postconditions: None
'
'----------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swDisplayDimension As SldWorks.DisplayDimension
Dim swDimension As SldWorks.Dimension
Dim swDimensionTolerance As SldWorks.DimensionTolerance
Dim fontHeight As Double
Dim fontScale As Double
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
'Get the selection
Set swDisplayDimension = swSelMgr.GetSelectedObject6(1,
0)
' If selection is not a dimension, then exit
If swSelMgr.GetSelectedObjectType3(1,
-1) <> swSelDIMENSIONS Then Exit Sub
' Selection is a dimension, so get the dimension tolerance
Set swDimension = swDisplayDimension.GetDimension
Set swDimensionTolerance = swDimension.Tolerance
' Get some dimension tolerance values
fontHeight = swDimensionTolerance.GetFontHeight
Debug.Print "Height of font =
" & fontHeight * 1000#; " mm"
fontScale = swDimensionTolerance.GetFontScale
Debug.Print "Scale of font =
" & fontScale
End Sub