以下是一个解决方案。它首先从零件或装配衍生,删除所有内部细节。然后利用该衍生件创建一个临时的非参数化零件。该零件内部的所有集合特征都被抑制。
VBA
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)
CalloPartDoc.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 InoPartDoc.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
CalloPartDoc.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