Hide Table of Contents

Replace Sketch Entity Example (VBA)

This example shows how to replace a sketch entity in a model with another sketch entity.

'----------------------------------------------------------------------------
' Preconditions: Verify that the specified template exists.
'
' Postconditions:
' 1. Opens a new part and creates Boss-Extrude1.
' 2. Replaces a sketch line with a sketch arc and modifies
'    Boss-Extrude1.
' 3. Examine the graphics area.
'---------------------------------------------------------------------------
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim myFeature As SldWorks.Feature
Dim skSegment As SldWorks.SketchSegment
Dim boolstatus As Boolean
Option Explicit

Sub main()

    Set swApp = _
    Application.SldWorks
   

    Set Part = swApp.NewDocument("C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2022\templates\Part.prtdot", 0, 0, 0)
    Set Part = swApp.ActiveDoc
 

    boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", -0.048646278525398, 2.22864804840025E-02, 1.05288722478765E-02, False, 0, Nothing, 0)
    Dim vSkLines As Variant
    vSkLines = Part.SketchManager.CreateCornerRectangle(-3.38155129850894E-02, 1.67825138518592E-02, 0, 5.51067619016271E-02, -2.45475575743612E-02, 0)
    Part.ClearSelection2 True
    Part.SketchManager.InsertSketch True
    Part.ShowNamedView2 "*Trimetric", 8
    boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 4, Nothing, 0)
   

    Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, 0.01778, 0.00254, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, True, True, True, 0, 0, False)
    Part.SelectionManager.EnableContourSelection = False
    boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
    Part.EditSketch
    Part.ClearSelection2 True
   

    Set skSegment = Part.SketchManager.Create3PointArc(-0.033816, 0.016783, 0#, 0.055107, 0.016783, 0#, 0.016009, 0.025458, 0#)
    Part.ClearSelection2 True

    boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 2.02904300411839E-03, 1.19654152286464E-02, -7.09549576220667E-03, True, 0, Nothing, 0)
    boolstatus = Part.Extension.SelectByID2("Arc1", "SKETCHSEGMENT", 5.88878331207997E-03, 1.71023327681304E-02, -1.26221740799126E-02, True, 0, Nothing, 0)

    ' Replace Line1 with Arc1, delete Line1, and make Arc1 a contour
    boolstatus = Part.SketchManager.SketchReplace2(False, True)

    Part.SketchManager.InsertSketch 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:   Replace Sketch Entity 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) 2022 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.