Author Topic: Best way to handle a document change event while command is active?  (Read 1991 times)

0 Members and 1 Guest are viewing this topic.

Atook

  • Swamp Rat
  • Posts: 1027
  • AKA Tim
Noticed today that if the user switches active drawing while one of my commands is active, I get an eLock violation.

Testing AutoCAD's built in commands, they don't handle the switch consistently. The polyline command just ends at the last point, and the insert command disables switching active drawings.

What's the best way to handle this?

I like the idea of locking the active drawing to current drawing, but not sure the best way to implement that via the .NET API.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Best way to handle a document change event while command is active?
« Reply #1 on: November 21, 2018, 10:05:58 AM »
I like the dotSmack method.  Give the user a smack for not finishing the active command before switching documents.  Eventually they'll get the hint, kind of like not shutting your fingers in the door.   :crazy2:
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

n.yuan

  • Bull Frog
  • Posts: 348
Re: Best way to handle a document change event while command is active?
« Reply #2 on: November 21, 2018, 10:21:10 AM »
AutoCAD 2015 introduced this big change: switching active document cancels most active command, due to the removal of the "fiber" stuff (naturally many existing custom CAD apps, be it LISP/VBA/.NET were broken then). If your custom command has Session flag, it may or may not be cancelled by document switch, depending on what the command does.

I had a few projects I wrote for pre-Acad2015 version broke when moved to Acad2015 or later and had to fix them. One scenario in my case is: during a command execution, user needs to go to another drawing to pick something and then return back to continue. I discussed it in my blog:

https://drive-cad-with-code.blogspot.com/2017/04/asking-user-to-select-entity-in-other.html
https://drive-cad-with-code.blogspot.com/2017/04/asking-user-to-select-entity-in-other_4.html

Atook

  • Swamp Rat
  • Posts: 1027
  • AKA Tim
Re: Best way to handle a document change event while command is active?
« Reply #3 on: November 26, 2018, 05:08:39 PM »
dgorsman, I'd love this dotSmack method! Despite hours in the Object Browser, I haven't been able to locate the dll to implement user.smack(trout). Any clues?  :uglystupid2:

Thanks for the posts Norman, interesting that you were having users switch between documents mid command. Cool approach. Don't let dgorsman find out....

Turns out the issue was that I was missing a documentlock when resetting a layer after a PromptResult was cancelled. Not sure why the error wasn't being thrown  when I exited via esc. Maybe the document switch killed the command's document lock before it finished? Not sure, but I know how to fix it at least.