Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
J-Camper
in reply to: mcloughlin_b

@mcloughlin_b,

 

Another option is to "dig" into sub assemblies until you get to the occurrence you are actually looking for, then return once it is selected.  Here is a simple example:

Sub Main
	Dim aDoc As AssemblyDocument = TryCast(ThisApplication.ActiveDocument, AssemblyDocument)
	If IsNothing(aDoc) Then Logger.Debug("ActiveDocument type is not: " & CType(aDoc.Type, ObjectTypeEnum).ToString)
	
	Dim targetOccurrence As ComponentOccurrence = DigTillPickCorrectly()
	If Not ThisApplication.ActiveEditDocument Is aDoc Then aDoc.ComponentDefinition.ActiveOccurrence.ExitEdit(ExitTypeEnum.kExitToTop)
	If IsNothing(targetOccurrence) Then Logger.Debug("Nothing Selected") : Exit Sub
		
	MessageBox.Show("Selected Occurrence: " & targetOccurrence.Name, "Result")

End Sub

Function DigTillPickCorrectly() As ComponentOccurrence
	Pick :
	Dim PickOccurrence As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select An Occurrence")
	If IsNothing(PickOccurrence) Then Return Nothing ' If nothing gets selected then we're done
	If PickOccurrence.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject
		Answer = MessageBox.Show("Selected Occurrence: " & PickOccurrence.Name & " is an Assembly, would you like to pick an occurrence within this Assembly? ", "Dig Deeper?",MessageBoxButtons.YesNo)
		If Answer = vbYes Then PickOccurrence.Edit() : GoTo Pick
	End If
	Return PickOccurrence
End Function

 

Let me know if you have any questions.