I'm currently developing an AutoCAD 2008 Addin in Visual Basic (.Net 3.0, VisualStudio 2010).
I'm able to define my own command and I want the user to be able to cancel my command by hitting the ESC key.
In AutoCAD 2010 or higher there exists the
HostApplicationServices.Current.UserBreak
method. But not in ACAD 2008.
Does anyone has any suggestions, h开发者_如何学运维ow the user may be able to cancel my command?
Not sure if this is what your looking for, but I'll throw it out there. In the following example, it prompts the user for input and stores it to the getPointResult. If the user selects "Escape" at this time, the getPointResult.Status will not be PromptStatus.OK, therefor it will not execute the code in the 'if' statement.
Sorry, this is written in C#, but should be easy enough to understand the general idea.
[CommandMethod("test", CommandFlags.Session)]
public void Test()
{
PromptPointOptions getPointOptions = new PromptPointOptions("Select the top-left location for the view: ");
Document currentDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
PromptPointResult getPointResult = currentDocument.Editor.GetPoint(getPointOptions);
if (getPointResult.Status == PromptStatus.OK)
{
//Do work
}
else
{
//what to do if 'ESC' is pressed during GetPoint()
}
}
精彩评论