Get Features of Multibody Sheet Metal Part Example (VB.NET)
This example shows how to get the number and names of the features in
a multibody sheet metal part.
'---------------------------------------------------------------------------
' Preconditions: A multibody sheet metal part is open.
'
' Postconditions: Compare the results printed to the
' Immediate
window with the bodies and
' features
in the sheet metal solid bodies folder.
'---------------------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System
Imports System.Diagnostics
Partial Class SolidWorksMacro
Public
Sub main()
Dim
swModel As ModelDoc2
Dim
swFeatMgr As FeatureManager
Dim
swFeat As Feature
Dim
swBodyFolder As BodyFolder
Dim
swBody As Body2
Dim
FeatType As String
Dim
FeatTypeName As String
Dim
Bodies As Object
Dim
Features As Object
Dim
i As Long
Dim
j As Long
swModel
= swApp.ActiveDoc
swFeatMgr
= swModel.FeatureManager
swFeat
= swModel.FirstFeature
Do
While Not swFeat Is Nothing
FeatType
= swFeat.Name
FeatTypeName
= swFeat.GetTypeName2
Debug.Print("
"
& FeatType & " [" & FeatTypeName & "]")
If
FeatTypeName = "SolidBodyFolder" Then
swBodyFolder
= swFeat.GetSpecificFeature2
Bodies
= swBodyFolder.GetBodies
Debug.Print("
Number
of bodies: " & swBodyFolder.GetBodyCount)
For
i = 0 To (swBodyFolder.GetBodyCount
- 1)
swBody
= Bodies(i)
Features
= swBody.GetFeatures
Debug.Print("
Number
of features in body #" & i + 1 & ": " & swBody.GetFeatureCount)
For
j = 0 To (swBody.GetFeatureCount
- 1)
Debug.Print("
Name
of feature: " & Features(j).GetTypeName2)
Next
j
Next
i
End
If
swFeat
= swFeat.GetNextFeature
Loop
End
Sub
'''
<summary>
'''
The SldWorks swApp variable is pre-assigned for you.
'''
</summary>
Public
swApp As SldWorks
End Class