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