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
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
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
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
(Not an Autodesk Employee)
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
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.