Hide Table of Contents

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



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get Chamfer Display Dimension Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2012 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.