That is the principle I was going for originally. The issue is that the "ON" action defines an infinite loop. BTW, I used
this as inspiration for the plugin. That code moves the while loop into the command Execute method, which opens the dialog and imediately starts the selection process. My idea however was to enable a more comprehensive renumbering app:
The original basically hard-coded the selection filters to only Rooms, Doors, Windows & Spaces (through a drop-down box and delegate functions [read similar to lambda's in lisp]). But my idea was to let the user pick an entity type by selecting an entity with bound parameters (i.e. I don't need to code for any new entity types at all), then read all the paramaters of text type and list them in a drop-down. That way the user can renumber anything - not just room numbers or door/window marks, but even view reference numbers placed on sheets, or comments for walls (whatever he/she likes) ... without coding anything extra for each scenario (as Adam Nagy's code needs to do).
So my form has another button on it to select the element type. This already works fine since it only calls the PickElement member, filters only elements which have bound text parameters (i.e. only those can get highlighted) and then polulates the paramater drop-down with their names. It also reads from a dictionary saved to the project settings as a string list to check which property was last used for that element type - a form of multiple defaults.
But due to my method, I can't have the form as for the actual click-and-increment all the time as Adam's is doing. Thus I've got a Run button. But the method of PickElement means it loops infinitely (i.e. while (true)), then jumps out of that loop through a try-catch on an ESC key press. The problem here is that such closes the dialog as well - which is generally not what the user wants to do (not in this case that is).
And having a 2-button / Run/Stop button doesn't stop the current iteration of the loop itself. Even with the state variable the PickElement method call is already waiting. So in this case the user needs to press the Stop button, then also pick something in the view (even if it's a blank spot) - simply to have the PickElement return so the loop can continue and see that the state has changed then break from the loop.
I was hoping these would be some sort of event I could turn on. Perhaps on the document. Something like
doc.OnPickElements += MyPickElementEventHandler;
That way the run action woult += such event, while the stop action would -= it. And the event handler would perform the actual action.
Though I can also see a problem with that: how to instantiate the filter object in such a case? Perhaps this is why ADesk didn't include such an event.
Edit: Sorry for all the typo's - new keyboard, new pc, new job, need to get used to it I guess.