Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swDwg As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swDispDim As SldWorks.DisplayDimension
Dim swDim As SldWorks.Dimension
Dim sCurSuffix As String
Dim nOpenParPos As Long
Dim nCloseParPos As Long
Dim vDimVal As Variant
Dim dInchVal As Double
Dim sInchString As String
Dim sNewSuffix As String
Const DUALFORMAT As String = "0.00"
Dim KillFlag As Integer
Dim sMsg As String
Sub main()
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
If swDoc.GetType <> swDocDRAWING Then
MsgBox "This macro only works for drawing files."
Exit Sub
End If
sMsg = "This macro will add a text suffix of the inch value with """ & _
vbCrLf & "to all dimensions in this drawing. This assumes that" & _
vbCrLf & "this drawing is dimensioned in millimeters" & vbCrLf & vbCrLf & _
"To add or update inch value suffixes inside ""[ ]"", choose ""Yes""" & vbCrLf & _
"To remove all inch value suffixes, including the ""[ ]"", choose ""No""" & _
vbCrLf & "To quit, choose ""Cancel"""
KillFlag = MsgBox(sMsg, vbYesNoCancel, "Add inch value?")
If KillFlag = vbCancel Then
Exit Sub
End If
Set swDwg = swDoc
Set swView = swDwg.GetFirstView
While Not (swView Is Nothing)
Set swDispDim = swView.GetFirstDisplayDimension5
While Not swDispDim Is Nothing
Set swDim = swDispDim.GetDimension
vDimVal = swDim.GetValue3(swThisConfiguration, Empty)
dInchVal = vDimVal(0) / 25.4
sInchString = Format(dInchVal, DUALFORMAT)
sCurSuffix = swDispDim.GetText(swDimensionTextSuffix)
nOpenParPos = InStr(1, sCurSuffix, "[", vbTextCompare)
nCloseParPos = InStr(1, sCurSuffix, "]", vbTextCompare)
If (KillFlag = vbNo) And (nOpenParPos > 0) And (nCloseParPos > 0) Then
sNewSuffix = Left(sCurSuffix, nOpenParPos - 1)
sNewSuffix = sNewSuffix & Right(sCurSuffix, Len(sCurSuffix) - nCloseParPos)
ElseIf (nOpenParPos > 0) And (nCloseParPos > 0) Then
sNewSuffix = Left(sCurSuffix, nOpenParPos)
sNewSuffix = sNewSuffix & sInchString & """"
sNewSuffix = sNewSuffix & Right(sCurSuffix, Len(sCurSuffix) - (nCloseParPos - 1))
Else
If KillFlag <> vbNo Then
sNewSuffix = "[" & sInchString & """] " & sCurSuffix
Else
sNewSuffix = sCurSuffix
End If
End If
swDispDim.SetText swDimensionTextSuffix, sNewSuffix
Set swDispDim = swDispDim.GetNext5
Wend
Set swView = swView.GetNextView
Wend
End Sub