AnsweredAssumed Answered

Macro to read a basic dimension

Question asked by Steve Cotterill on Sep 11, 2020
Latest reply on Sep 12, 2020 by Eddy Alleman

Hello All,


I would like to have a macro that reads a dimension, modifies certain parameters and writes them back to the dimension to comply with the company standard.  This will only apply to selected dimensions on a drawing.


I am able to read/modify/write to the dimension textprefix, textsuffix, TextCalloutBelow

I am able to write to the DimensionLowerText, but not read it.


has anyone been able to read the DimensionLowerText of a dimension (this is the red highlighted text in the attachment).


Thanks in advance,




The code I have is as follows: - 


Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim boolstatus As Boolean
Dim selMgr As SelectionMgr
Dim swDispDim As SldWorks.DisplayDimension
Dim swDim As SldWorks.Dimension
Dim PrefixText As String
Dim SuffixText As String
Dim CalloutBelowText As String
Dim DimensionLowerText As String
Option Explicit

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set selMgr = swModel.SelectionManager
Debug.Print selMgr.GetSelectedObjectType(1)
Set swDispDim = selMgr.GetSelectedObject6(1, 0)

'Read parameters of selected drawing dimension
PrefixText = swDispDim.GetText(swDimensionTextParts_e.swDimensionTextPrefix) 'Orange Highlighted Text
Debug.Print "Prefix = " & PrefixText
SuffixText = swDispDim.GetText(swDimensionTextParts_e.swDimensionTextSuffix) 'Green Highlighted Text
Debug.Print "Suffix = " & SuffixText
CalloutBelowText = swDispDim.GetText(swDimensionTextParts_e.swDimensionTextCalloutBelow) 'Blue Highlighted Text
Debug.Print "Callout Below Text = " & CalloutBelowText
'DimensionLowerText = swDispDim.GetText(swDimensionTextParts_e.swDimensionLowerText) 'Red Highlighted Text..........doesn't work
' Debug.Print "Lower Text = " & DimensionLowerText

'Modify Parameters
PrefixText = "(2x) " & PrefixText
DimensionLowerText = "NO IDEA WHAT THIS IS" & DimensionLowerText 'this is only to prove that i can write to that part of the dimension

'Write new Parameters to dimension
Set swDim = swDispDim.GetDimension

boolstatus = swModelDocExt.EditDimensionProperties(0, 0, 0, "", "", True, 9, 2, True, 12, 12, PrefixText, SuffixText, True, "", CalloutBelowText, DimensionLowerText, False, 0, "")
swModel.ClearSelection2 True

End Sub