> Autodimension a Sketch Example (VBA)
Welcome
Getting Started
SolidWorks API Help
FeatureWorks API Help
SolidWorks Document Manager API Help
eDrawings API Help
SolidWorks Routing API Help
SolidWorks Simulation API Help
SolidWorks Utilities API Help
SolidWorks Workgroup PDM API Help
Hide Table of Contents Show 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



Related SolidWorks Forum Content

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:  
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

The search functionality within the web help is in a beta test phase and you may experience periodic delays or interruptions in its performance. These are the normal and ordinary features of a beta test and shall not under any circumstances give rise to any liability on the part of DS SolidWorks or its licensors. The topics within the Web-based help are not beta topics; they document 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.