Files
Demonstration of important IFeature members
Code
'Determine feature types, getting their FeatureData interfaces, and getting specific feature _
types. Also looks like interface inheritance between IFeature and specific features.
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
'Precondition: part with several features is open.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swParentFeat As SldWorks.Feature
Dim swChildFeat As SldWorks.Feature
Dim swSketch As SldWorks.Sketch
Dim swComp As SldWorks.Component2
Dim swBody As SldWorks.Body2
Dim vBodies As Variant
Dim vBodiesInfo As Variant
Dim vChildFeats As Variant
Dim swExtrudeFeatData As SldWorks.ExtrudeFeatureData2
Dim i As Integer
Dim z As Integer
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swParentFeat = swModel.FirstFeature
While Not swParentFeat Is Nothing
vChildFeats = swParentFeat.GetChildren
Debug.Print "Parent: " & swParentFeat.Name & " (" & swParentFeat.GetTypeName & ")"
If IsEmpty(vChildFeats) = False Then
For i = 0 To UBound(vChildFeats)
Set swChildFeat = vChildFeats(i)
Debug.Print " " & swChildFeat.Name & " (" & swChildFeat.GetTypeName & ")"
If swChildFeat.GetTypeName = "ProfileFeature" Then
Set swSketch = swChildFeat.GetSpecificFeature2
Debug.Print " Sketch name: " & swSketch.Name 'interface inheritance"
End If
Next i
End If
'for assemblies, does not affect sub-assy's, only top level
If swParentFeat.GetTypeName = "Reference" Then
Set swComp = swParentFeat.GetSpecificFeature2
'proof that interface inheritance doesn't exist between IFeature and IComponent
'Debug.Print swComp.Description
vBodies = swComp.GetBodies3(swSolidBody, vBodiesInfo)
If IsEmpty(vBodies) = False Then
For z = 0 To UBound(vBodies)
Set swBody = vBodies(z)
Debug.Print " Face count: " & swBody.GetFaceCount
Next z
End If
End If
Set swParentFeat = swParentFeat.GetNextFeature
Wend
End Sub
'NOTES:
'It appears that GetTypeName can return all of the same data as GetTypeName2 even though _
certain newer features are only listed under GetTypeName2.
'The return values of GetTypeName(2) are case sensitive.
'This will work in an assembly as well. To get the component, use GetSpecificFeature2.
'Interface inheritance doesn't work with IComponent2
'GetTypeName
'Component --> "Reference"
'Sketch --> "ProfileFeature"
'Boss extrusion --> "Boss"
'Base extrusion --> "Extrusion"