Inventor 2023 : Find the assembly or subassembly that contains the selected part.

Inventor 2023 : Find the assembly or subassembly that contains the selected part.

vpeuvion
Advocate Advocate
346 Views
2 Replies
Message 1 of 3

Inventor 2023 : Find the assembly or subassembly that contains the selected part.

vpeuvion
Advocate
Advocate

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.

 

0 Likes
Accepted solutions (1)
347 Views
2 Replies
Replies (2)
Message 2 of 3

Curtis_Waguespack
Consultant
Consultant
Accepted 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

EESignature

Message 3 of 3

vpeuvion
Advocate
Advocate

Hi @Curtis_Waguespack,

Thank you for your reply.

This answers my problem. Thanks for the help.

Vincent.

0 Likes