Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling AutoCAD commands from C#.NET

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.

like image 616
Nick Gilbert Avatar asked Mar 31 '15 14:03

Nick Gilbert


People also ask

What are the ways to call a command in AutoCAD?

Enter a Command on the Command Line Enter the command using one of the following options: In the Command prompt text box, type the full command name and press Enter or Spacebar.

What is Ctrl Shift C in AutoCAD?

Ctrl+Shift+C. Copy to clipboard with base point. Ctrl+Shift+V. Paste data as block.

How do you call a command box in AutoCAD?

Solution: Use the shortcut CTRL+9 (CMD+3 in AutoCAD for Mac) to toggle on the command line.


1 Answers

When you use SendCommand you always need a space at the end, that will make sure the command runs.

Also, on AutoCAD 2015 (and newer) you can user Editor.Command or Editor.CommandAsync, which is much better.

http://adndevblog.typepad.com/autocad/2014/04/migration-after-fiber-is-removed-in-autocad-2015.html

like image 149
Augusto Goncalves Avatar answered Sep 29 '22 01:09

Augusto Goncalves