Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
vpeuvion
242 Views, 2 Replies

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

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.

 

2 REPLIES 2
Message 2 of 3

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

Message 3 of 3

Hi @Curtis_Waguespack,

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.

Post to forums  

Autodesk Design & Make Report