Allows access to a sheet metal normal cut feature.
'VBA
'*******************************************************************
'1. Open c:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2019\samples\whatsnew\sheet metal\normal_cut.sldprt.
'2. Open the Immediate window.
'3. Run the macro.
'4. Creates Normal Cut1 in the FeatureManager design tree.
'5. Edits the feature by specifying a normal cut direction entity.
'6. Inspect the Immediate window.
'****************************************************************
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swFeatMgr As SldWorks.FeatureManager
Dim swFeat As SldWorks.Feature
Dim swNormalCutFeatData As SldWorks.SMNormalCutFeatureData2
Dim grpData As SldWorks.SMNormalCutGroupData
Dim swSelMgr As SldWorks.SelectionMgr
Dim swCutDirectionFace As SldWorks.Face2
Dim errCode As Long
Dim boolstatus As Boolean
Dim varGrpNames As Variant
Dim i As Long
Dim j As Long
Dim Name As String
Dim Face As SldWorks.Face2
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set swFeatMgr = swModel.FeatureManager
Set swNormalCutFeatData = swFeatMgr.CreateDefinition(swFmNormalCut)
swNormalCutFeatData.AutoPropagation = True
swNormalCutFeatData.OptimizeGeometry = True
swNormalCutFeatData.NormalCutParameters = swNormalCutExtent
' Select the face(s) to make normal
boolstatus = swModel.Extension.SelectByRay(4.71296104838217E-02, 1.42054003862171E-02, -6.68923799798904E-03, -0.13322686545804, 0.182153484913837, 0.974202602261958, 6.19874904830013E-04, 2, True, 1, 0)
Set grpData = swNormalCutFeatData.CreateGroup(errCode)
' Create the normal cut feature
Set swFeat = swFeatMgr.CreateFeature(swNormalCutFeatData)
' Modify the normal cut feature
Set swNormalCutFeatData = swFeat.GetDefinition()
swNormalCutFeatData.AccessSelections swModel, Nothing
varGrpNames = swNormalCutFeatData.GetGroupNames()
For i = 0 To UBound(varGrpNames)
Name = varGrpNames(i)
Debug.Print "GroupName: " & Name
Set grpData = swNormalCutFeatData.GetGroupByName(Name)
Dim varFaces As Variant
varFaces = grpData.Faces
For j = 0 To UBound(varFaces)
Set Face = varFaces(j)
Debug.Print "Face " & j & " area: " & Face.GetArea
Next j
Debug.Print "--------------------"
Next i
'Specify the cut direction
Set swSelMgr = swModel.SelectionManager
boolstatus = swModel.Extension.SelectByRay(-0.149999999999892, 2.58556514245498E-02, -4.63505465353364E-03, 0.393242668518252, 0.12460738379391, -0.910951811876282, 1.22626958447854E-03, 2, False, 0, 0)
Set swCutDirectionFace = Nothing
Set swCutDirectionFace = swSelMgr.GetSelectedObject6(1, -1)
Dim swSelectEnt As SldWorks.Entity
Set swSelectEnt = swCutDirectionFace
boolstatus = swSelectEnt.Select4(False, Nothing)
swNormalCutFeatData.CutDirection = swCutDirectionFace
Dim isModified As Boolean
isModified = swFeat.ModifyDefinition(swNormalCutFeatData, swModel, Nothing)
End Sub