Calling AutoCAD Undo commands from C#.NET

Calling AutoCAD Undo commands from C#.NET

Anonymous
Not applicable
3,969 Views
3 Replies
Message 1 of 4

Calling AutoCAD Undo commands from C#.NET

Anonymous
Not applicable

I'm trying to write two methods which call AutoCAD's UNDO command and pass in different parameters. The first method calls UNDO and passes M which means mark the position of the drawing. The second method calls UNDO and passes B which means undo all the way back to the marked position (or the end if there isnt one). So far they are pretty simple

        /// <summary>
        /// Method to mark the current position of the AutoCAD program
        /// </summary>
        public static void MarkPosition()
        {            doc.SendStringToExecute("._UNDO M", true, false, true);
        }

        /// <summary>
        /// Method to step AutoCAD back int steps
        /// </summary>
        public static void BigUndo()
        {            doc.SendStringToExecute("._UNDO B", true, false, true);
        }

These look like they should work but for some reason they don't. When I call MarkPosition() and then BigUndo() I get an error saying Start of Group encountered; enter Undo End to go back further. To test my syntax. I changed MarkPosition to

public static void MarkPosition() 
{    doc.SendStringToExecute("circle 2,2,0 4 ", true, false, true);
}

which successfully draws a circle. That means my syntax is right but something weird is going on with Undo.

3,970 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Does anyone have an answer for this? I also have the same issue.

 

I've tried:

 

acDoc.SendStringToExecute("undo 1 ", true, false, false);
acDoc.SendStringToExecute("._UNDO 1 ", true, false, false);
0 Likes
Message 3 of 4

_gile
Consultant
Consultant

Hi,

 

Difficult to diagnose with so few details about the error (if any), the context, etc.

The main issue while using SendStringToExecute is it runs asynchronously.

For AutoCAD 2015 or later, you can try to use the Editor.Command() method, for prior version you can use Tony  Tanzillo's wrapper for the non-public RunCommand() method, both work the same.

 

acDoc.Editor.Command("_.undo", 1);

 

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 4

Anonymous
Not applicable

It does work with Editor.Command() as well as I'd like it to, thanks.

0 Likes