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: 

Assembly SelectSet - Get component name

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
bryan_schmuland
176 Views, 4 Replies

Assembly SelectSet - Get component name

I would like to select a plane or planes in an assembly document, and get the name of both the plane and the component it belongs to.

 

I have found some code which lets me get the name of the selected object (the plane) but from this I haven't been able to find out how to get the component name.  My end goal is to take the selected plane and apply a constraint.

Dim oAD As AssemblyDocument
Dim oSelected As SelectSet

oAD = ThisApplication.ActiveDocument
oSelected = oAD.SelectSet
    
For Each item In oSelected
   MessageBox.Show(item.name & " - " )
Next
4 REPLIES 4
Message 2 of 5

Hi @bryan_schmuland 

Give this a try.

 

 

 

Dim oAD As AssemblyDocument
Dim oSelected As SelectSet

oAD = ThisApplication.ActiveDocument
oSelected = oAD.SelectSet
    
For Each item As ComponentOccurrence In oSelected
   MessageBox.Show(item.name & " - " )
Next

 

Message 3 of 5

I was working on it at the same time apparently, so I will go ahead and post what I have too. 😁

Sub Main
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Return
	Dim oSS As SelectSet = oADoc.SelectSet
	If oSS.Count = 0 Then Return
	Dim oSelected = oSS.Item(1)
	If TypeOf oSelected Is WorkPlaneProxy Then
		Dim oWPP As WorkPlaneProxy = oSelected
		Dim sWPName As String = oWPP.NativeObject.Name
		Dim oOcc As ComponentOccurrence = oWPP.ContainingOccurrence
		Dim sOccName As String = oOcc.Name
		MsgBox("Component Name = " & sOccName & vbCrLf & _
		"WorkPlane Name = " & sWPName)
	End If
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 5

This is great! Thanks
Message 5 of 5

I realized just after posting my code above, that most of the variables you would want to be working with are all defined within the If...Then statement, so would not be available outside of that block of code.  Here is a better version of that code that minimizes that block of code, and leaves you with usable variables afterwards.

Sub Main
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then
		MsgBox("An assembly was not obtained, so exiting rule.", vbCritical, "iLogic")
		'Logger.Debug("An assembly was not obtained, so exiting rule.")
		Return
	End If
	Dim oSS As SelectSet = oADoc.SelectSet
	If oSS.Count = 0 Then
		MsgBox("Nothing was pre-selected.", vbCritical, "iLogic")
		'Logger.Debug("Nothing was pre-selected.")
		Return
	End If
	Dim oWPP As WorkPlaneProxy = Nothing
	If TypeOf oSS.Item(1) Is WorkPlaneProxy Then oWPP = oSS.Item(1)
	If oWPP Is Nothing Then
		MsgBox("Pre-selected object was not a WorkPlaneProxy.", vbCritical, "iLogic")
		'Logger.Debug("Pre-selected object was not a WorkPlaneProxy.")
		Return
	End If
	Dim sWPName As String = oWPP.NativeObject.Name
	Dim oOcc As ComponentOccurrence = oWPP.ContainingOccurrence
	Dim sOccName As String = oOcc.Name
	MsgBox("Component Name = " & sOccName & vbCrLf & _
	"WorkPlane Name = " & sWPName)
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report