Question

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, how the user may be able to cancel my command?

Was it helpful?

Solution

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()
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top