Author Topic: Cancel current command from palette and preserve pickfirst?  (Read 340 times)

0 Members and 1 Guest are viewing this topic.

Atook

  • Swamp Rat
  • Posts: 917
Cancel current command from palette and preserve pickfirst?
« on: December 24, 2018, 12:31:54 AM »
I've got palettes with buttons that call commands with a SendStringToExecute call.

Looks like:
Code - C#: [Select]
  1. SendStringToExecute("\x03\x03MyCommand ", true, false, false);

I added the \x03\x03 to the beginning of the string to cancel any current commands.

I'm almost embarrassed to admit how much time it took to figure out that the \x03\x03 is killing the pickfirst (SelectImplied()) selection.  :uglystupid2:

Any suggestions for a good way to execute a command from a palette, cancelling any current commands when the button is pressed, AND preserve the pickfirst selectionset?

huiz

  • Swamp Rat
  • Posts: 826
  • Certified Prof C3D
Re: Cancel current command from palette and preserve pickfirst?
« Reply #1 on: December 24, 2018, 01:23:42 AM »
You can check if the Editor is idle, so you don't have to cancel any command. In case of an active command, you can show a messagebox or loop through escapes until there is no command active. I can remember there are rare cases where you need even three escapes before a command is canceled but I can't remember which.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

n.yuan

  • Bull Frog
  • Posts: 269
Re: Cancel current command from palette and preserve pickfirst?
« Reply #2 on: December 24, 2018, 11:27:47 AM »
In one of my recent articles( https://drive-cad-with-code.blogspot.com/2018/10/executing-command-from-paletteset.html ), I discussed the same topic, similar as the other reply suggested: test if there is active command in progress or not, and only send "\x30\x30" with SendStringToExecute() to cancel that command, instead of calling SendStringToExecute with "\x30\x30" prefixed command string. This way, as long as there is no active command in progress, the command started from PaletteSet with SendStringToExecute() will pick up the PickFirst select set, when the command has CommandFlags.UsePickSet flag set.

Atook

  • Swamp Rat
  • Posts: 917
Re: Cancel current command from palette and preserve pickfirst?
« Reply #3 on: December 25, 2018, 03:38:54 PM »
Thanks guys, what an easy solution! Norman, thanks for writing it up in your blog, it's a valuable resource for us .NET CAD people

Here's what I've come up with in my commands class:
Code - C#: [Select]
  1. /// <summary>
  2. /// Sends the command via SendStringToExecute
  3. /// To preserve pickfirst, cancel only if there is an active command.
  4. /// </summary>
  5. /// <param name="cmd">The command to send.</param>
  6. public static void Send(string cmd)
  7. {
  8.  Document doc = CAD_App.DocumentManager.MdiActiveDocument;
  9.  if (doc == null) return;
  10.  // gotta have a space at the end.
  11.  if (!cmd.EndsWith(" ")) cmd += " ";
  12.  // check for active command
  13.  int activeCmd = Convert.ToInt32(CAD_App.GetSystemVariable("CMDACTIVE"));
  14.  if (activeCmd > 0)
  15.  {
  16.    // cancel out of it
  17.    doc.SendStringToExecute("\x03\x03", false, true, false);
  18.  }
  19.  // now send the command we want
  20.  doc.SendStringToExecute(cmd, false, true, false);
  21. }

And it's called from a pallet with something like:
Code - C#: [Select]
  1. private void btnSetSize_Click(object sender, EventArgs e)
  2. {
  3.  Commands.Send("IR_SetPipeSize");
  4. }

There could be a problem with the back to back SendStringToExecute calls since I think it's async, but I haven't seen any issues so far.
« Last Edit: December 25, 2018, 07:56:13 PM by Atook »