Issue
Is there an example showing how to delete faces from a part using the Inventor API?
Solution
It is possible to delete the face from a part using the Inventor API. This is done by adding the faces to the DeleteFaceFeatures. A FaceCollection object is created and the faces to be deleted are added to the collection. Finally the collection is added to the DeleFaceFeature object.
VBA code:
Sub deleteSideFaces_VBA()
'remove all the side faces
Dim aDoc As Document
Dim pFets As PartFeatures
Dim cdef As ComponentDefinition
Dim oExtrude As ExtrudeFeatures
Dim oAllface As Face
Set aDoc = _
ThisApplication.ActiveDocument
Set cdef = _
aDoc.ComponentDefinition
Set pFets = _
cdef.Features
Set oExtrude = _
pFets.ExtrudeFeatures
'FaceCollection to hold the faces to delete
Dim oFacecoll As FaceCollection
Set oFacecoll = _
ThisApplication.TransientObjects.CreateFaceCollection
Dim oFaces As Faces
Set oFaces = _
oExtrude.Item(1).SideFaces
'Add all the sideface of the part in
' to the face collection object
For Each oAllface In oFaces
oFacecoll.Add oAllface
Next
'delete the faces by adding into the deleteFaceFeatures
If oFacecoll.Count > 0 Then
pFets.DeleteFaceFeatures.Add oFacecoll, False
End If
End Sub
VB.NET code:
Sub deleteSideFaces()
' assume we have had Inventor application
' _InvApplication
'remove all the side faces
Dim aDoc As Document =
_InvApplication.ActiveDocument
Dim cdef As ComponentDefinition =
aDoc.ComponentDefinition
Dim pFets As PartFeatures =
cdef.Features
Dim oExtrude As ExtrudeFeatures =
pFets.ExtrudeFeatures
'FaceCollection to hold the faces to delete
Dim oFacecoll As FaceCollection
oFacecoll =
_InvApplication.TransientObjects.CreateFaceCollection
Dim oFaces As Faces
oFaces = oExtrude.Item(1).SideFaces
Dim oAllface As Face
'Add all the sideface of the part in
‘to the face collection object
For Each oAllface In oFaces
oFacecoll.Add(oAllface)
Next
'delete the faces by adding into the deleteFaceFeatures
If oFacecoll.Count > 0 Then
pFets.DeleteFaceFeatures.Add(oFacecoll, False)
End If
End Sub