只显示模型的外轮廓

模型太大,都会影响性能,而有时只是查看模型,并不需要内部细节,可以采取提取轮廓的方式来简化模型,提高效率。

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

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

VB.NET Code

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 = TrueThen

            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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值