Get Chamfer Display Dimension Example (VBA)
This example shows how to get chamfer display dimension properties.
'-----------------------------------------------------------------------------
' Preconditions:
' 1. Open <SolidWorks_install_dir>\samples\tutorial\api\plate_tolstatus.sldprt.
' 2. Create a drawing from the part:
' a. File > Make Drawing from Part.
' b. Drag and drop the isometric view onto
the sheet.
' 3. Create a chamfer display dimension.
' a. Select Tools > Dimensions > Chamfer.
' b. Select a chamfer edge first and a
leading edge second.
' c. Click off the part to place the display
dimension.
' d. Modify display dimension text in the PropertyManager:
' i. In Dimension
Text, click before <DIM>.
' ii. Select the diameter
symbol.
' iii. Click after <DIM>.
' iv. Select the +/-
symbol.
' v. Type 0.5.
' vi. On the Other tab
select Override Units.
' vii. Click the green check
mark to accept the display dimension.
' 4. Open an Immediate Window.
'
' Postconditions: Inspect the Immediate Window.
'
' NOTE: Because the part document is used by other macros,
' do not save any changes when closing it.
'------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swDispDim As SldWorks.DisplayDimension
Dim bRet As Boolean
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
bRet = swModel.Extension.SelectByID2("RD1@Drawing View1",
"DIMENSION", 0.4935677398765, 0.3280800260301, 0, False, 0, Nothing, 0)
Set swDispDim = swSelMgr.GetSelectedObject6(1, 0)
swModel.ClearSelection2 True
Debug.Print "Dimension type as defined in swDimensionType_e:
" & swDispDim.Type2 '10=swChamferDimension
Debug.Print ""
Debug.Print "Uses document units? " & swDispDim.GetUseDocUnits 'false if uses
local override units
If swDispDim.GetUseDocUnits = False Then
Dim LenUnit As Long
Dim AngUnit As Long
bRet = swDispDim.GetChamferUnits(LenUnit, AngUnit)
Debug.Print "Uses local length unit as defined in
swLengthUnits_e: " & LenUnit '0=swMM
Debug.Print "Uses local angle unit as defined in
swAngleUnits_e: " & AngUnit '0=swDegrees, 3=swRadians
End If
Debug.Print ""
Dim indx As Long
indx = swDispDim.ChamferPrecision(0)
Debug.Print "Precision of chamfer distance: " & indx & " decimal places"
indx = swDispDim.ChamferPrecision(1)
Debug.Print "Precision of chamfer angle: " & indx & " decimal places"
Dim tokenformats As Variant
Dim tokenvalues As Variant
Dim tokenformat As String
Dim n As Long
Debug.Print ""
Debug.Print "Text format items in " & swDispDim.GetNameForSelection & ":"
Debug.Print ""
Dim count As Long
count =
swDispDim.GetTextFormatItems(swDimensionTextParts_e.swDimensionTextCalloutAbove,
tokenformats, tokenvalues)
Debug.Print "Number of callout above items: " & count
If Not count = 0 Then
Debug.Print " tokenformats: "
For n = LBound(tokenformats) To UBound(tokenformats)
Debug.Print " " &
tokenformats(n)
Next n
Debug.Print " tokenvalues: "
For n = LBound(tokenvalues) To UBound(tokenvalues)
Debug.Print " " &
tokenvalues(n)
Next n
End If
Debug.Print ""
count =
swDispDim.GetTextFormatItems(swDimensionTextParts_e.swDimensionTextPrefix,
tokenformats, tokenvalues)
Debug.Print "Number of prefix items: " & count
If Not count = 0 Then
Debug.Print " tokenformats: "
For n = LBound(tokenformats) To UBound(tokenformats)
Debug.Print " " &
tokenformats(n)
Next n
Debug.Print " tokenvalues: "
For n = LBound(tokenvalues) To UBound(tokenvalues)
Debug.Print " " & tokenvalues(n)
Next n
End If
Debug.Print ""
count =
swDispDim.GetTextFormatItems(swDimensionTextParts_e.swDimensionTextSuffix,
tokenformats, tokenvalues)
Debug.Print "Number of suffix items: " & count
If Not count = 0 Then
Debug.Print " tokenformats: "
For n = LBound(tokenformats) To UBound(tokenformats)
Debug.Print " " &
tokenformats(n)
Next n
Debug.Print " tokenvalues: "
For n = LBound(tokenvalues) To UBound(tokenvalues)
Debug.Print " " & tokenvalues(n)
Next n
End If
Debug.Print ""
count =
swDispDim.GetTextFormatItems(swDimensionTextParts_e.swDimensionTextCalloutBelow,
tokenformats, tokenvalues)
Debug.Print "Number of callout below items: " & count
If Not count = 0 Then
Debug.Print " tokenformats: "
For n = LBound(tokenformats) To UBound(tokenformats)
Debug.Print " " &
tokenformats(n)
Next n
Debug.Print " tokenvalues: "
For n = LBound(tokenvalues) To UBound(tokenvalues)
Debug.Print "" & tokenvalues(n)
Next n
End If
End Sub