Replace Dimension with Text Example (VBA)
This example shows how to temporarily replace the selected dimension
with text.
'----------------------------------------------------------------
'
' Preconditions:
' (1)
Drawing is open.
' (2)
Dimension is selected.
'
' Postconditions: Selected dimension is replaced by display
text.
'
'----------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim
model As SldWorks.ModelDoc2
Dim
selMgr As SldWorks.SelectionMgr
Dim
selObj As Object
Dim
selType As Long, selCount As Long
Dim
selDim As SldWorks.DisplayDimension
Dim
textFont As SldWorks.TextFormat
Dim
entType As Long
Dim
triData(0 To 8) As Double, vEntData As Variant
Dim
dotData(0 To 3) As Double, arcData(0 To 11) As Double, textPos(0 To 2)
As Double
Dim
boolstatus As Boolean
Sub main()
Set
swApp = Application.SldWorks
Set
model = swApp.ActiveDoc
Set
selMgr = model.SelectionManager
selCount
= selMgr.GetSelectedObjectCount()
If
selCount > 0 Then
selType
= selMgr.GetSelectedObjectType2(1)
Set
selObj = selMgr.GetSelectedObject5(1)
If
selType = SwConst.swSelDIMENSIONS Then
Set
selDim = selObj
triData(0)
= 0.12
triData(1)
= 0.1
triData(2)
= 0#
triData(3)
= 0.15
triData(4)
= 0.1
triData(5)
= 0#
triData(6)
= 0.13
triData(7)
= 0.13
triData(8)
= 0#
vEntData
= triData
boolstatus
= selDim.AddDisplayEnt(2, (vEntData))
'
Filled triangle
dotData(0)
= 0.11
dotData(1)
= 0.14
dotData(2)
= 0#
dotData(3)
= 0.005
vEntData
= dotData
boolstatus
= selDim.AddDisplayEnt(6, (vEntData))
'
Filled dot
dotData(0)
= 0.16
dotData(1)
= 0.14
dotData(2)
= 0#
dotData(3)
= 0.009
vEntData
= dotData
boolstatus
= selDim.AddDisplayEnt(6, (vEntData))
'
Filled dot
arcData(0)
= 0.135
arcData(1)
= 0.11
arcData(2)
= 0#
arcData(3)
= 0#
arcData(4)
= 0#
arcData(5)
= 1#
arcData(6)
= 0.09
arcData(7)
= 0.11
arcData(8)
= 0#
arcData(9)
= 0.18
arcData(10)
= 0.11
arcData(11)
= 0#
vEntData
= arcData
boolstatus
= selDim.AddDisplayEnt(4, (vEntData))
'
Arc
textPos(0)
= 0.09
textPos(1)
= 0.065
textPos(2)
= 0#
vEntData
= textPos
Set
textFont = model.GetUserPreferenceTextFormat(SwConst.swDetailingDimensionTextFormat)
textFont.CharHeightInPts
= 48
boolstatus
= selDim.AddDisplayText("Hi!",
(vEntData), textFont, SwConst.swTextJustificationCenter, 1#)
End
If
Else
MsgBox
("Dimension selection required")
End
If
End Sub