Hide Table of Contents

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



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:   Replace Dimension with Text 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.