Retrieve the parent file name of an ipart member

Retrieve the parent file name of an ipart member

keithjk
Advocate Advocate
1,015 Views
4 Replies
Message 1 of 5

Retrieve the parent file name of an ipart member

keithjk
Advocate
Advocate

This should be easy but I am having trouble figuring it out.

 

I need to get the filename of the ifactory parent file for a given ipart member.  I need it work for both .ipt and .iam iparts.

 

Below is a start on my code.  The section I need help with is underlined in red.

 

Private Sub TestThis ()

 Dim oDocPart As PartDocument = Nothing

 Dim oDocAssembly As AssemblyDocument = Nothing

 

 If oInventorApp.ActiveDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject Then

    oDocPart = oInventorApp.ActiveDocument

  Debug.Print("This is a part document. The filename is:" & oDocPart.FullDocumentName)

  If oDocPart.ComponentDefinition.IsiPartMember Then

   'get the file name of the parent part (that contains the iPart table)

  ElseIf oInventorApp.ActiveDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then

     oDocAssembly = oInventorApp.ActiveDocument

  If oDocAssembly.ComponentDefinition.IsiAssemblyMember Then

   'get the file name of the parent part (that contains the iPart table)

  Else

  'not and .ipt or .iam so exit

   Exit Sub

  End If

 End If

End If

End Sub

Accepted solutions (1)
1,016 Views
4 Replies
Replies (4)
Message 2 of 5

HermJan.Otterman
Advisor
Advisor
Accepted solution

Hello Keith,

 

here is your code....

 

Private Sub TestThis()

Dim oDoc As Inventor.Document = _inventorApplication.ActiveDocument

If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then

Dim oPartDoc As PartDocument = TryCast(oDoc, PartDocument)

 

If oPartDoc.ComponentDefinition.IsiPartMember = True Then

'get the file name of the parent part (that contains the iPart table)

Dim ParentName As String = oPartDoc.ReferencedDocumentDescriptors(1).DisplayName

MsgBox(ParentName)

End If

ElseIf oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then

Dim oAssyDoc As AssemblyDocument = TryCast(oDoc, AssemblyDocument)

If oAssyDoc.ComponentDefinition.IsiAssemblyMember = True Then

'get the file name of the parent part (that contains the iPart table)

Dim ParentName As String = oAssyDoc.ReferencedDocumentDescriptors(1).DisplayName

MsgBox(ParentName)

Else

'not and .ipt or .iam so exit

Exit Sub

End If

End If

End Sub

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 3 of 5

Anonymous
Not applicable

Perfect!


Thank you!

0 Likes
Message 4 of 5

HermJan.Otterman
Advisor
Advisor

great that is works...

 

would you kindly please choose "exept as solution"

so others can see that there is a solution,

and I get my satisfaction Smiley Happy

 

thanks

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 5 of 5

danielvdeleito
Contributor
Contributor

Simple way how to get the filename of an occurrence by position in the tree:

oDoc = ThisDoc.Document
oOccs = oDoc.ComponentDefinition.Occurrences
Dim occ As ComponentOccurrence
occ = oOccs.Item(1)'this is the occurrence number
Dim memberDoc As PartDocument
memberDoc = occ.Definition.Document
Dim factoryDoc As PartDocument
factoryDoc = memberDoc.ComponentDefinition.iPartMember.ReferencedDocumentDescriptor.ReferencedDocument
ParentName = factoryDoc.DisplayName
0 Likes