I tried the macro.
It shows runtime error '91' obj variable not set...
Just a short input to this old thread as I used this code just recently. Mike's code works fine as long as the last feature is flat pattern. If I had other features below the flat pattern, I received an error. So I changed the code a little, and now it worked for me in all cases. This is it:
'Traverse SubFeatures Example
'This example shows how to Traverse the Sub-Features
'of each feature in a Part .
Dim swApp As SldWorks.SldWorks
Dim swPart As SldWorks.ModelDoc2
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
'Get the 1st feature in part
Dim Feature As SldWorks.Feature
Set Feature = Part.FirstFeature
Dim FeatureCount As Integer
FeatureCount = 0
' While we have a valid feature
While Not Feature Is Nothing
' Get the name of the feature
Dim FeatureName As String
Dim FeatureType As String
Dim SubFeat As SldWorks.Feature
FeatureType = Feature.GetTypeName2
If FeatureType = "FlatPattern" Then
Set SubFeat = Feature.GetFirstSubFeature
' While we have a valid Sub-feature
While Not SubFeat Is Nothing
' Get the type of the Sub-feature
If SubFeat.GetTypeName2 = "UiBend" Then
FeatureCount = FeatureCount + 1
Set SubFeat = SubFeat.GetNextSubFeature
' Continue until the last Sub-feature is done
' Get the next feature
Set Feature = Feature.GetNextFeature
MsgBox FeatureCount & " bends in this part"
'add a custom property
'Part.AddCustomInfo3 "", "Number of Bends", swCustomInfoText, CStr(FeatureCount)
Retrieving data ...