Hi,
I'm trying to find the assembly that contains the selected part.
Until now, I use a code where I select a face, from this face, I find the part document and from the part document, I find the assembly document which contains it. I do it following these steps because I need the face and part for other operations. It works well when I only have one assembly open. If another assembly that contains the part is opened, I may end up with the wrong result since I am using item 1.
Is there an easy way to find the assembly or subassembly that contains the selected part?
Attached is a simplified extract of the code :
Sub Main() Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Face") If oFace Is Nothing Then Exit Sub Dim oPartDoc As PartDocument = oFace.Parent.ComponentDefinition.Document Dim oAsm As AssemblyDocument = oPartDoc.ReferencingDocuments.Item(1) MessageBox.Show(oAsm.DisplayName) End Sub
Thanks. Vincent.
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi @vpeuvion
The native object of the parent of the parent should provide you the correct object.
I just realized this wasn't returning what I thought it was... I'll try and have another look later
update: see version below that uses the ParentOccurrence of the parent.parent
Sub Main Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Face") If oFace Is Nothing Then Exit Sub If TypeOf oFace.Parent.Parent Is ComponentOccurrenceProxy Then MessageBox.Show(oFace.Parent.Parent.ParentOccurrence.name) ElseIf TypeOf oFace.Parent.Parent Is ComponentOccurrence MessageBox.Show(oFace.Parent.Parent.Parent.Document.Displayname ) End If End Sub
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Thank you for your reply.
This answers my problem. Thanks for the help.
Vincent.
Can't find what you're looking for? Ask the community or share your knowledge.