Hide Table of Contents

Remove Sketch Contour from Feature Example (VBA)

This example shows how to remove the first selected contour, which can be a sketch contour or sketch region, from an extrude feature made up of multiple sketch contours or sketch regions.

NOTE:  This same code will work for a revolve feature made up of multiple sketch contours or sketch regions in its base sketch if you modify IModelDocExtension::SelectByID2 and the variable ext.

 

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

'

' Preconditions:

'          1) Part document is open.

'          2) Part contains a base sketch with multiple sketch contours or sketch

'             regions or both.

'          3) Extrude1 feature was created using sketch regions or

'             sketch contours of base sketch.

'

' Postconditions: None

'

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

Option Explicit

 

Dim swApp As SldWorks.SldWorks

Dim Part As SldWorks.ModelDoc2

Dim boolstatus As Boolean

 

Sub main()

 

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

boolstatus = Part.Extension.SelectByID2("Extrude1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, swSelectOptionDefault)

 

Dim feat As Feature

Dim ext As ExtrudeFeatureData2

Dim cts As Variant

Set feat = Part.SelectionManager.GetSelectedObject5(1)

Set ext = feat.GetDefinition

ext.AccessSelections Part, Nothing

 

' Get the selected contours in the feature

cts = ext.Contours

' Get the first selected contour in the feature and mark it

cts(0).Select False, 0

 

Dim cr As SketchRegion

Dim ct As SketchContour

 

' Determine if the first selected contour in the feature
' is either a sketch region or a sketch contour

If TypeOf cts(0) Is SketchRegion Then

    Set cr = cts(0)

Else

    Set ct = cts(0)

End If

 

' Assign Nothing to the first selected contour in the feature

Set cts(0) = Nothing

' Update the selected contours in the feature

ext.Contours = cts

' Modify the feature by removing the first selected contour in the feature

boolstatus = feat.ModifyDefinition(ext, Part, Nothing)

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:   Remove Sketch Contour from Feature 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) 2013 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.