How to Identify the Parent of a Derived Component After Assembly Simplification?

How to Identify the Parent of a Derived Component After Assembly Simplification?

Ivan_Sinicyn
Advocate Advocate
269 Views
1 Reply
Message 1 of 2

How to Identify the Parent of a Derived Component After Assembly Simplification?

Ivan_Sinicyn
Advocate
Advocate

I’m currently working with derived components in Inventor and trying to determine the parent document of a derived part. My script works well for standard DerivedPartComponent and DerivedAssemblyComponent cases using the ReferencedDocumentDescriptor.FullDocumentName property. However, I’ve encountered an issue with components created through assembly simplification.

When a derived component results from an assembly simplification, it seems the parent relationship is not as straightforward. The usual methods to retrieve the parent document (like DerivedPartComponent or ReferencedDocuments) don’t seem to work reliably for these cases.

Could someone clarify:

  1. What is the best method or API property to determine the parent document of a derived component after assembly simplification?
  2. Is there a specific property or workflow to handle simplified assemblies and their derived components?

 

 

Sub Main()
    ' Get the active document
    Dim activeDoc As Document = ThisApplication.ActiveDocument

    ' Check if the document is a PartDocument
    If Not TypeOf activeDoc Is PartDocument Then
        MessageBox.Show("This script only works for PartDocuments.", "Error")
        Return
    End If

    Dim partDoc As PartDocument = CType(activeDoc, PartDocument)
    Dim compDef As PartComponentDefinition = partDoc.ComponentDefinition

    ' Check for derived components
    If compDef.ReferenceComponents.DerivedPartComponents.Count > 0 Then
        ' Process DerivedPartComponents
        Dim derivedComp As DerivedPartComponent = compDef.ReferenceComponents.DerivedPartComponents(1)
        Dim parentDocPath As String = derivedComp.ReferencedDocumentDescriptor.FullDocumentName
        MessageBox.Show("Parent document path: " & parentDocPath & vbCrLf & "Method: DerivedPartComponent", "Result")
    ElseIf compDef.ReferenceComponents.DerivedAssemblyComponents.Count > 0 Then
        ' Process DerivedAssemblyComponents
        Dim derivedAsmComp As DerivedAssemblyComponent = compDef.ReferenceComponents.DerivedAssemblyComponents(1)
        Dim parentAsmPath As String = derivedAsmComp.ReferencedDocumentDescriptor.FullDocumentName
        MessageBox.Show("Parent document path: " & parentAsmPath & vbCrLf & "Method: DerivedAssemblyComponent", "Result")
    Else
        ' Check for source document in referenced documents
        Dim refDocs As DocumentsEnumerator = activeDoc.ReferencedDocuments
        Dim foundParent As Boolean = False

        For Each refDoc As Document In refDocs
            If refDoc.DocumentType = kPartDocumentObject Or refDoc.DocumentType = kAssemblyDocumentObject Then
                ' Output the path to the found parent document
                MessageBox.Show("Parent document path: " & refDoc.FullDocumentName & vbCrLf & "Method: ReferencedDocuments", "Result")
                foundParent = True
                Exit For
            End If
        Next

        If Not foundParent Then
            MessageBox.Show("Unable to determine the parent document for this derived component.", "Information")
        End If
    End If
End Sub

 

 

Here's an example, but I think it may cause problems in other scenarios.

INV 2025.3
0 Likes
Accepted solutions (1)
270 Views
1 Reply
Reply (1)
Message 2 of 2

C_Haines_ENG
Collaborator
Collaborator
Accepted solution

Does this code work for you? This seems to work with both derived components and simplified assemblies.

Sub Main
	
	Dim oDoc As PartDocument = ThisDoc.Document
	
	For Each oRefDoc As DocumentDescriptor In oDoc.ReferencedDocumentDescriptors
		
		MsgBox(oRefDoc.FullDocumentName)
		
	Next

End Sub