Cancelling a pending command line before calling Editor.GetPoint
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello people,
I'm working on an application that run as an AutoCAD palette. Among various things, my palette has some buttons working as shortcut for some command line like "PAN" ou "ZOOM W", some other making more complex things, including waiting for the user to select a point with Editor.GetPoint(), and a Cancel button.
Each of my control button begin with a cancellation command to be sure we clear any running command before going for the next.
Before AutoCAD 2015, my cancellation sub was a call to acedPostCommand("CANCELCMD") and everything was fine. It's not supported anymore and I have some trouble to replace it with something working every time.
For now, my solution is to send some escape character with Document.SendStringToExecute. The last case that doesn't work is when there is a pending command line and I try to cancel it before making an Editor.GetPoint in the same call. The cancellation fails and the GetPoint immediately returns a PromptStatus.Cancel. If I make a cancellation alone (with my cancel button), it works.
What do I miss ?
Here's a code example for clarity :
public partial class PaletteTest : UserControl
{
public PaletteTest()
{
InitializeComponent();
}
private void buttonPANcmd_Click(object sender, EventArgs e)
{
CancelRunningCommand();
ApplicationServices.Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_.PAN ", true, false, true);
}
private void buttonZoomWcmd_Click(object sender, EventArgs e)
{
CancelRunningCommand();
ApplicationServices.Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_.ZOOM _.W ", true, false, true);
}
private void buttonGetPoint_Click(object sender, EventArgs e)
{
Document doc = ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
ApplicationServices.Application.DocumentManager.MdiActiveDocument.Window.Focus();
Debug.WriteLine("quiescent 1 : {0}", doc.Editor.IsQuiescent);
CancelRunningCommand(); // Fail to cancel any pending command line
Debug.WriteLine("quiescent 2 : {0}", doc.Editor.IsQuiescent);
PromptPointResult ppr = ed.GetPoint("click somewhere"); // immediately return PromptStatus.Cancel if there is a pending command line
if (ppr.Status != PromptStatus.OK)
return;
MessageBox.Show(string.Format("clicked on {0:N4}, {1:N4}", ppr.Value.X, ppr.Value.Y));
}
private void buttonCancel_Click(object sender, EventArgs e)
{
CancelRunningCommand();
}
private void CancelRunningCommand()
{
Document doc = ApplicationServices.Application.DocumentManager.MdiActiveDocument;
string cmds = (string)ApplicationServices.Application.GetSystemVariable("CMDNAMES");
string esc = string.Empty;
if (cmds.Length > 0)
{
// case of a command line command to be cancelled
int cmdNum = cmds.Split('\\').Length;
for (int i = 0; i < cmdNum ; i++)
{
esc += "\x03";
}
doc.SendStringToExecute(esc, true, false, true);
}
else if (! doc.Editor.IsQuiescent)
{
// case of a prompt to be cancelled
esc = "\x03";
doc.SendStringToExecute(esc, true, false, true);
}
else
{
// nothing to cancel
}
}
}