Modify Surface-cut Feature Example (VBA)
This example shows how to modify a surface-cut feature.
'-------------------------------------------------------------
' Preconditions: Open the Immediate window.
'
' Postconditions:
' 1. Direction of the surface-cut feature
' is flipped.
' 2. Examine the output to the Immediate window to verify
' that the surface-cut feature was flipped.
'
' NOTE: Because this part document is used elsewhere,
' do not save any changes when closing it.
'-------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeature As SldWorks.Feature
Dim swSurfCutFeature As SldWorks.SurfCutFeatureData
Dim status As Boolean
Dim errors As Long, warnings As Long
Dim fileName As String
Sub main()
Set swApp = Application.SldWorks
fileName = "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\samples\tutorial\api\SurfCut.sldprt"
swApp.OpenDoc6 fileName, swDocPART, swOpenDocOptions_Silent, "", errors, warnings
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
' Get the surface-cut feature
status = swModelDocExt.SelectByID2("SurfaceCut1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
Set swSelMgr = swModel.SelectionManager
Set swFeature = swSelMgr.GetSelectedObject6(1, -1)
Set swSurfCutFeature = swFeature.GetDefinition
status = swSurfCutFeature.AccessSelections(swModel, Nothing)
' Flip direction of surface cut
swSurfCutFeature.Flip = True
Debug.Print ("Surface-cut feature flipped: " & status)
' Update definition of feature
swFeature.ModifyDefinition swSurfCutFeature, swModel, Nothing
' Rebuild part
swModel.EditRebuild3
End Sub