- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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:
- What is the best method or API property to determine the parent document of a derived component after assembly simplification?
- 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.
Solved! Go to Solution.