MACRO LIBRARY

Get and set dimension text

Free public access. No account or subscription required.

Files

Get and set dimension text

Code

'Demonstrates how to get and set drawing dimension text
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
'Preconditions: Drawing contains single drawing view. Drawing view is of a model _
    with a hole wizard hole. That drawing view has a hole callout attached to it.
'Postconditions: See immediate window.
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swDim As SldWorks.DisplayDimension
Dim strDimText(9) As String
Dim i As Integer
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swDraw = swModel
    Set swView = swDraw.GetFirstView
    Set swView = swView.GetNextView
    Set swDim = swView.GetFirstDisplayDimension5
    
    'strDimText(0) need not be included because it is only used with _
        IDisplayDimension::SetText
    strDimText(1) = swDim.GetText(swDimensionTextParts_e.swDimensionTextCalloutAbove)
    strDimText(2) = swDim.GetText(swDimensionTextParts_e.swDimensionTextCalloutAboveDefinition)
    strDimText(3) = swDim.GetText(swDimensionTextParts_e.swDimensionTextCalloutBelow)
    strDimText(4) = swDim.GetText(swDimensionTextParts_e.swDimensionTextCalloutBelowDefinition)
    strDimText(5) = swDim.GetText(swDimensionTextParts_e.swDimensionTextPrefix)
    strDimText(6) = swDim.GetText(swDimensionTextParts_e.swDimensionTextPrefixDefinition)
    strDimText(7) = swDim.GetText(swDimensionTextParts_e.swDimensionTextSuffix)
    strDimText(8) = swDim.GetText(swDimensionTextParts_e.swDimensionTextSuffixDefinition)
    
    For i = 0 To 9
        If strDimText(i) = "" Then strDimText(i) = "Empty"
    Next i
    
    Debug.Print strDimText(0)
    Debug.Print strDimText(1)
    Debug.Print strDimText(2)
    Debug.Print strDimText(3)
    Debug.Print strDimText(4)
    Debug.Print strDimText(5)
    Debug.Print strDimText(6)
    Debug.Print strDimText(7)
    Debug.Print strDimText(8)
    
    'change text
    swDim.SetText swDimensionTextParts_e.swDimensionTextAll, "new text"
End Sub
    
'Notes: Members of swDimensionTextParts_e
    
'swDimensionTextAll                     Entire dimension text string _
                                            (IDisplayDimension::SetText only)
'swDimensionTextPrefix                  Prefix portion of the text
'swDimensionTextSuffix                  Suffix portion of the text
'swDimensionTextCalloutAbove            Callout-above portion of the text
'swDimensionTextCalloutBelow            Callout-below portion of the text
'swDimensionTextPrefixDefinition        Definition of the prefix portion of the text
'swDimensionTextSuffixDefinition        Definition of the suffix portion of the text
'swDimensionTextCalloutAboveDefinition  Definition of the callout portion of the _
                                            text above the dimension
'swDimensionTextCalloutBelowDefinition  Definition of the callout portion of the _
                                            text below the dimension