Invoking AutoCAD Commands from C # .NET

I am trying to write two methods that call the AutoCAD UNDO command and pass different parameters. The first method calls UNDO and passes M, which means marking the position of the drawing. The second method calls UNDO and passes B, which means the cancellation is completely back to the marked position (or the end if it is absent). 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); } 

They look as if they should work, but for some reason they do not. When I call MarkPosition () and then BigUndo (), I get the error "Start of group"; enter Undo End to go back. To check 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. This means that my syntax is right, but something strange is happening with Undo.

+6
source share
3 answers

When you use SendCommand, you always need a space at the end that will ensure the execution of the command.

In addition, at AutoCAD 2015 (and newer) you can use 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

+1
source

The space you submit is not recognized by AutoCAD as a new line. First you need to add a new line, and then send the next character in another line, as shown below:

  doc.SendStringToExecute("._UNDO\n", true, false, true); doc.SendStringToExecute("M\n", true, false, true); doc.SendStringToExecute("._UNDO\n", true, false, true); doc.SendStringToExecute("B\n", true, false, true); 
0
source

You are missing the @END space on the command line.

  doc.SendStringToExecute("._UNDO B", true, false, true); // Instead of this doc.SendStringToExecute("._UNDO B ", true, false, true); // use this 
0
source

Source: https://habr.com/ru/post/984504/


All Articles