03-02-2023
01:22 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
03-02-2023
01:22 PM
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.