Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
YuhanZhang
in reply to: dhaverstick

You can try below updated VBA code if it works, it will iterate all the sub occurrences and hide the derived part components:

 

Sub hideCurveOfDerivePart()
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
     
    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet
     
    Dim oView1 As DrawingView
    Set oView1 = oSheet.DrawingViews(1)
     
    Dim oModelDoc As Document
    Set oModelDoc = oView1.ReferencedDocumentDescriptor.ReferencedDocument
     
    If oModelDoc.DocumentType = kAssemblyDocumentObject Then
        Dim oEachOcc As ComponentOccurrence
        
        For Each oEachOcc In oModelDoc.ComponentDefinition.Occurrences
        
            'native part document (this part has derived part)
            If oEachOcc.ReferencedDocumentDescriptor.ReferencedDocument.DocumentType = kPartDocumentObject Then
                Dim oNativePartDoc As PartDocument
                Set oNativePartDoc = oEachOcc.ReferencedDocumentDescriptor.ReferencedDocument
             
                'check if the document has derived part
                If oNativePartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count > 0 Then
                    'hide the occurrence in the context of the drawing view.
                    Call oView1.SetVisibility(oEachOcc, False)
                End If
            ElseIf oEachOcc.ReferencedDocumentDescriptor.ReferencedDocument.DocumentType = kAssemblyDocumentObject Then
                Dim oSubOccu As ComponentOccurrence
                For Each oSubOccu In oEachOcc.SubOccurrences
                    HideDerivedComponent oSubOccu, oView1
                Next
            End If
        Next
    End If
End Sub

' Iterate all the sub occurrences and hide the derived part
Sub HideDerivedComponent(oOccu As ComponentOccurrence, oView As DrawingView)
    Dim oEachOcc As ComponentOccurrence
    
    If oOccu.ReferencedDocumentDescriptor.ReferencedDocument.DocumentType = kPartDocumentObject Then
        Dim oNativePartDoc As PartDocument
        Set oNativePartDoc = oOccu.ReferencedDocumentDescriptor.ReferencedDocument
 
        'check if the document has derived part
        If oNativePartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count > 0 Then
        'hide the occurrence in the context of the drawing view.
            Call oView.SetVisibility(oOccu, False)
        End If
    ElseIf oOccu.ReferencedDocumentDescriptor.ReferencedDocument.DocumentType = kAssemblyDocumentObject Then
        Dim oSubOccu As ComponentOccurrence
        For Each oSubOccu In oOccu.SubOccurrences
            HideDerivedComponent oSubOccu, oView
        Next
    End If
End Sub

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.