Issue
I would like to hide the complexity of my assemblies and parts by suppressing all the internal cavities that are present in the Inventor models and show only the visible external geometry. I want to do it, for example, to give to my customers an overview of my models, without actually providing any information about the internal design. How can this be achieved?
Solution
The following VBA sample addresses this problem by first creating a derived Part from the initial document, this one can be a Part or an Assembly, then it will deletes any internal closed cavity in the model. This transitional derived Part will then be used to create a final non-parametric Part in which the internal geometry is completely suppressed.
The transitional document is also saved on disk by the sample code, under the name “InitialDocName” + “_Boundary.ipt” but this step is not required. You could just generate the final document “InitialDocName” + “_BoudaryFinal.ipt” and close the derived Part without saving it.
Public Sub CreateExternalBoundary()
Dim oTopDoc As Document
Set oTopDoc = ThisApplication.ActiveDocument
Dim oTrans As Transaction
Set oTrans = ThisApplication.TransactionManager.StartTransaction(oTopDoc, "CreateExternalBoundary")
Dim oPartDoc As PartDocument
If oTopDoc.DocumentType = kAssemblyDocumentObject Then
' Create a new part document, invisibly.
Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, , True)
' Derive the assembly into the part.
Dim oDerivedAsmDef As DerivedAssemblyDefinition
Set oDerivedAsmDef = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(oTopDoc.FullDocumentName)
Call oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAsmDef)
Else
Set oPartDoc = oTopDoc
End If
'Find any voids within the solid and delete them.
Dim oVoidFaces As FaceCollection
Set oVoidFaces = ThisApplication.TransientObjects.CreateFaceCollection
Dim oShell As FaceShell
For Each oShell In oPartDoc.ComponentDefinition.SurfaceBodies.Item(1).FaceShells
If (oShell.IsVoid = True) Then
Dim oFace As Face
For Each oFace In oShell.Faces
oVoidFaces.Add oFace
Next
End If
Next
If oVoidFaces.Count > 0 Then
Call oPartDoc.ComponentDefinition.Features.DeleteFaceFeatures.Add(oVoidFaces)
End If
'Save the doc.
'At this point the internal cavities can still be seen by supressing the "DeleteFaceFeature"
Call oPartDoc.SaveAs(oTopDoc.FullFileName + "_Boundary.ipt", False)
'Create the final PartDocument as a NonParametric solid.
'This will definitely suppress the possibility to see the internal geometry of the initial document
Dim oMatrix As Matrix
Set oMatrix = ThisApplication.TransientGeometry.CreateMatrix()
Dim oBody As SurfaceBody
Set oBody = oPartDoc.ComponentDefinition.SurfaceBodies(1)
Dim oPartDocFinal As PartDocument
Set oPartDocFinal = ThisApplication.Documents.Add(kPartDocumentObject, , True)
Call oPartDocFinal.ComponentDefinition.Features.NonParametricBaseFeatures.Add(oBody, oMatrix)
Call oPartDocFinal.SaveAs(oTopDoc.FullFileName + "_BoundaryFinal.ipt", False)
oTrans.End
End Sub
Public Sub CreateExternalBoundary()
Dim m_inventorApp As Inventor.Application = Nothing
' Try to get an active instance of Inventor
Try
m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
Catch ex As Exception
End Try
' If not active, create a new Inventor session
If m_inventorApp Is Nothing Then
Dim inventorAppType As Type = System.Type.GetTypeFromProgID("Inventor.Application")
m_inventorApp = System.Activator.CreateInstance(inventorAppType)
End If
Dim oTopDoc As Document
oTopDoc = m_inventorApp.ActiveDocument
Dim oTrans As Transaction
oTrans = m_inventorApp.TransactionManager.StartTransaction(oTopDoc, "CreateExternalBoundary")
Dim oPartDoc As PartDocument
If oTopDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
' Create a new part document, invisibly.
oPartDoc = m_inventorApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True)
' Derive the assembly into the part.
Dim oDerivedAsmDef As DerivedAssemblyDefinition
oDerivedAsmDef = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(oTopDoc.FullDocumentName)
Call oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAsmDef)
Else
oPartDoc = oTopDoc
End If
'Find any voids within the solid and delete them.
Dim oVoidFaces As FaceCollection
oVoidFaces = m_inventorApp.TransientObjects.CreateFaceCollection
Dim oShell As FaceShell
For Each oShell In oPartDoc.ComponentDefinition.SurfaceBodies.item(1).FaceShells
If (oShell.IsVoid = True) Then
Dim oFace As Face
For Each oFace In oShell.Faces
oVoidFaces.Add(oFace)
Next
End If
Next
If oVoidFaces.count > 0 Then
Call oPartDoc.ComponentDefinition.Features.DeleteFaceFeatures.Add(oVoidFaces)
End If
'Save the doc.
'At this point the internal cavities can still be seen by supressing the "DeleteFaceFeature"
oPartDoc.SaveAs(oTopDoc.FullFileName + "_Boundary.ipt", False)
'Create the final PartDocument as a NonParametric solid.
'This will definitely suppress the possibility to see the internal geometry of the initial document
Dim oMatrix As Matrix
oMatrix = m_inventorApp.TransientGeometry.CreateMatrix()
Dim oBody As SurfaceBody
oBody = oPartDoc.ComponentDefinition.SurfaceBodies(1)
Dim oPartDocFinal As PartDocument
oPartDocFinal = m_inventorApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True)
oPartDocFinal.ComponentDefinition.Features.NonParametricBaseFeatures.Add(oBody, oMatrix)
oPartDocFinal.SaveAs(oTopDoc.FullFileName + "_BoundaryFinal.ipt", False)
oTrans.End()
End Sub