Hide Table of Contents

Autodimension a Sketch Example (VBA)

This example shows how to autodimension a sketch.

 

'----------------------------------------------------

' Preconditions:

'       (1) Part or assembly is open.

'       (2) Sketch is being edited.

'       (3) Sketch contains some sketch segments or geometry.

'       (4) At least two sketch entities are selected.

'       (5) First selected sketch entity is used for horizontal datum.

'       (6) Second selected sketch entity is used for vertical datum.

'

' Postconditions: If successful, then dimensions are added to sketch.

'

' NOTES: Return code from ISketch::AutoDimension2 is output to

' debug window and you should examine the code in the case of failure.

'

'----------------------------------------------------

Option Explicit

 

Public Enum swAutodimEntities_e

    swAutodimEntitiesAll = 1

    swAutodimEntitiesSelected = 2

End Enum

Public Enum swAutodimMark_e

    swAutodimMarkEntities = &H1

    swAutodimMarkHorizontalDatum = &H2

    swAutodimMarkVerticalDatum = &H4

End Enum

Public Enum swAutodimScheme_e

    swAutodimSchemeBaseline = 1

    swAutodimSchemeOrdinate = 2

    swAutodimSchemeChain = 3

    swAutodimSchemeCenterline = 4

End Enum

Public Enum swAutodimHorizontalPlacement_e

    swAutodimHorizontalPlacementBelow = -1

    swAutodimHorizontalPlacementAbove = 1

End Enum

Public Enum swAutodimVerticalPlacement_e

    swAutodimVerticalPlacementLeft = -1

    swAutodimVerticalPlacementRight = 1

End Enum

Public Enum swAutodimStatus_e

    swAutodimStatusSuccess = 0

    swAutodimStatusBadOptionValue = 1

    swAutodimStatusNoActiveDoc = 2

    swAutodimStatusDocTypeNotSupported = 3

    swAutodimStatusNoActiveSketch = 4

    swAutodimStatus3DSketchNotSupported = 5

    swAutodimStatusSketchIsEmpty = 6

    swAutodimStatusSketchIsOverDefined = 7

    swAutodimStatusNoEntities = 8

    swAutodimStatusEntitiesNotValid = 9

    swAutodimStatusCenterlineNotAllowed = 10

    swAutodimStatusDatumNotSupplied = 11

    swAutodimStatusDatumNotUnique = 12

    swAutodimStatusDatumNotValidType = 13

    swAutodimStatusDatumLineNotCenterline = 14

    swAutodimStatusDatumLineNotVertical = 15

    swAutodimStatusDatumLineNotHorizontal = 16

    swAutodimStatusAlgorithmFailed = 17

End Enum

 

Sub main()

 

    Dim swApp                           As SldWorks.SldWorks

    Dim swModel                         As SldWorks.ModelDoc2

    Dim swSelMgr                        As SldWorks.SelectionMgr

    Dim swSketch                        As SldWorks.sketch

    Dim swSketchSegHoriz                As SldWorks.SketchSegment

    Dim swSketchSegVert                 As SldWorks.SketchSegment

    Dim nRetVal                         As Long

    Dim i                               As Long

    Dim bRet                            As Boolean

    

    Set swApp = CreateObject("SldWorks.Application")

    Set swModel = swApp.ActiveDoc

    Set swSketch = swModel.GetActiveSketch2

    Set swSelMgr = swModel.SelectionManager

    Set swSketchSegHoriz = swSelMgr.GetSelectedObject5(1)

    Set swSketchSegVert = swSelMgr.GetSelectedObject5(2)

    

    swModel.ClearSelection2 True

    

    ' Reselect sketch segments with correct marks

    ' for auto-dimensioning

    bRet = swSketchSegHoriz.Select3(True, swAutodimMarkHorizontalDatum, Nothing)

    bRet = swSketchSegVert.Select3(True, swAutodimMarkVerticalDatum, Nothing)

    

    nRetVal = swSketch.AutoDimension2( _

                    swAutodimEntitiesAll, _

                    swAutodimSchemeBaseline, _

                    swAutodimHorizontalPlacementBelow, _

                    swAutodimSchemeBaseline, _

                    swAutodimVerticalPlacementLeft)

    Debug.Print "  AutoDim = " & nRetVal

    

    ' Redraw so dimensions are displayed immediately

    swModel.GraphicsRedraw2

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:   Autodimension a Sketch 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.