Get DisplayName of a parent's part

Get DisplayName of a parent's part

Anonymous
Not applicable
519 Views
3 Replies
Message 1 of 4

Get DisplayName of a parent's part

Anonymous
Not applicable

Is there a way to get all the Display Name of a Parent's Part or Assembly using a VBA "Inventor 2019".

 

i tried to extract the compenent but i don't know how to get the parents :

Private Sub CommandButton1_Click()
    
    Dim OApp As Inventor.Application
    Set OApp = GetObject(, "Inventor.Application")

    Dim oDoc As Document
    Set oDoc = OApp.ActiveDocument
    Dim oAllrefdocs As DocumentsEnumerator
    Set oAllrefdocs = oDoc.ReferencedFiles

    Dim oSubDoc As Document
    Dim oSubDoc1 As Document
    Dim sMsg As String
    Dim iLeafNodes As Long
    Dim iSubAssemblies As Long

    Dim i As Integer

For i = 1 To oAllrefdocs.Count

    ListBox1.AddItem oAllrefdocs.Item(i).DisplayName         
     
Next
End Sub
0 Likes
520 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

i get the parent name of level N+1

Sub test()

Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
Dim Parent As Document
Set Parent = oDoc.ReferencingDocuments.Item(1)
MsgBox (Parent.DisplayName)

End Sub

But i would like to get all the displayname's parents of all levels

 

thank you in advance. 

0 Likes
Message 3 of 4

Anonymous
Not applicable

i get the parent name of level N+1

Sub test()

Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
Dim Parent As Document
Set Parent = oDoc.ReferencingDocuments.Item(1)
MsgBox (Parent.DisplayName)

End Sub

But i would like to get all the displayname's parents of all levels

 

thank you in advance. 

0 Likes
Message 4 of 4

Sergio.D.Suárez
Mentor
Mentor

Hi, Here is an example of how to get the father of each occurrence within an assembly.
I have not tried it, but I think it should work.

 

Sub Main() 
    ' Get the active assembly. 
    Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument 
    ' Call the function that does the recursion. 
    Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1) 
End Sub 

Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer) 
    ' Iterate through all of the occurrence in this collection.  This 
    ' represents the occurrences at the top level of an assembly. 
    For Each oOcc As ComponentOccurrence In Occurrences 
        ' Check to see if this occurrence represents a subassembly 
        ' and recursively call this function to traverse through it. 
        If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then 
            Call TraverseAssembly(oOcc.SubOccurrences, Level + 1) 
        End If 
		Try
			Dim oParentocc As ComponentOccurrence
			oParentocc = oOcc.ParentOccurrence
			oParent = oParentocc.DisplayName
		Catch
			oParent = System.IO.Path.GetFileNameWithoutExtension(oOcc.Parent.Document.DisplayName)
		End Try
		oData = oParent & "@" & oOcc.Name & "@" & "Level - " & Level
			MessageBox.Show(oData)
	Next 
End Sub

 Tell me a little about what you want to achieve to see if I can help you
regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes