PickfirstSelectionSet Workaround

I found many posts about PickfirstSelectionSet not working properly, so when I found a solution for myself I thought I should share it.
I use a lisp to launch my macro. The lisp I use to launch my macro calls another lisp before activating my desired VBA Sub. The lisp called senses if anything is currently selected. If anything is selected, it calls a macro to set a global variable ("UseActive") to true, and if nothing is selected it sets that variable to false. Then it launches my Sub. When my sub runs it checks UseActive. If UseActive is false the sub has the user select items; if UseActive is true the sub uses ThisDrawing.ActiveSelectionSet (which contains the items that were selected when the user started the command).
Lisp Routines:
(defun C:CurrentlySelected() (if (ssget "I") (vl-vbarun "CurrentSelection") (vl-vbarun "NotCurrentSelection")) )
(defun C:Mir2x () (C:CurrentlySelected) (vl-vbarun "mir2") )
VBA Code:
Dim UseActive As Boolean
Public Sub NotCurrentSelection() UseActive = False End Sub
Public Sub CurrentSelection() UseActive = True End Sub
Public Sub SelectionSetRemove(SetName As String) Dim a As AcadSelectionSet
For Each a In ThisDrawing.SelectionSets If StrComp(a.Name, SetName, 1) = 0 Then a.Delete Exit For End If Next a End Sub
Public Sub mir2()
Dim AttHolder() Dim Curr_Obj As AcadObject Dim Mird_Obj As AcadObject Dim AttLocs() Dim AttTemp(0 To 1) Dim Mird_AttLocs() Dim MiringTargets As AcadSelectionSet
On Error Resume Next
If UseActive = True Then Set MiringTargets = ThisDrawing.ActiveSelectionSet Else Err.Clear Set MiringTargets ThisDrawing.SelectionSets.Add("ReservedUserSetForStarting") If Err.Number <> 0 Then Err.Clear SelectionSetRemove ("ReservedUserSetForStarting") Set MiringTargets ThisDrawing.SelectionSets.Add("ReservedUserSetForStarting") End If MiringTargets.SelectOnScreen End If ...
And then on to the rest of my program.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
Add image file

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.