Hide Table of Contents

Move Copy Sketch Entities Example (VBA)

This example shows how to move, copy, and move and copy sketch entities.

 

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

'

' Preconditions: Model document that has a sketch

'                named Sketch1 is open and that sketch

'                has Arc1 and Line1 entities.

'

' Postconditions: None

'

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

Option Explicit

 

Dim swApp As SldWorks.SldWorks

 

Sub main()

 

    Dim swModel            As SldWorks.ModelDoc2

    Dim swModelExtension   As SldWorks.ModelDocExtension

    Dim swPart             As SldWorks.PartDoc

    Dim swFeature          As SldWorks.Feature

    Dim swSketchMgr        As SldWorks.SketchManager

    Dim bValue             As Boolean

    Dim lIdx               As Long

    Dim bCopy              As Boolean

    Dim lNumCopies         As Long

    Dim aBasePoint(2)      As Double

    Dim aMoveVector(2)     As Double

    

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc    

    Set swModelExtension = swModel.Extension    

    Set swPart = swModel

    Set swSketchMgr = swModel.SketchManager

    

    Set swFeature = swPart.FeatureByName("Sketch1")

    bValue = swFeature.Select2(False, 0)

    swModel.EditSketch

    

    aBasePoint(0) = 0#

    aBasePoint(1) = 0#

    aBasePoint(2) = 0#

 

    aMoveVector(0) = 0.1

    aMoveVector(1) = 0#

    aMoveVector(2) = 0#

    

    For lIdx = 0 To 2

        swModel.ClearSelection2 True

        bValue = swModelExtension.SelectByID2("Arc1", "SKETCHSEGMENT", 0#, 0#, 0#, False, 0, Nothing, 0)

        bValue = swModelExtension.SelectByID2("Line1", "SKETCHSEGMENT", 0#, 0#, 0#, True, 0, Nothing, 0)

        Select Case (lIdx)

            Case 0

' Move

                bCopy = False

                lNumCopies = 0

            Case 1

' Move and copy once

                bCopy = True

                lNumCopies =

            Case 2

' Move and copy twice

                bCopy = True

                lNumCopies = 2

        End Select

        If (Not bCopy) Then

            lNumCopies = 0

        End If

        swModelExtension.MoveOrCopy bCopy, lNumCopies, True, aBasePoint(0), aBasePoint(1), 0#, aBasePoint(0) + aMoveVector(0), aBasePoint(1) + aMoveVector(1), aBasePoint(2) + aMoveVector(2)

        swModel.ClearSelection2 True

        ' Examine the model document to see what has changed

        Stop

        ' Undo so that you can do it again, but differently

        swModel.EditUndo2 1

    Next lIdx

    swSketchMgr.Insert3DSketch True    

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:   Move Copy Sketch Entities 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.