You can send commands directly to the AutoCAD command line by using the SendStringToExecute method. The SendStringToExecute method sends a single string to the command line. The string must contain the arguments to the command listed in the order expected by the prompt sequence of the executed command.
使用 SendStringToExecute 方法可以直接将命令发送到 AutoCAD 命令行。SendStringToExecute 方法将单个字符串发送到命令行。该字符串必须包含提供给所执行命令的参数,并依照该命令的提示顺序所要求的次序排列这些参数。
A blank space or the ASCII equivalent of a carriage return in the string is equivalent to pressing Enter on the keyboard. Unlike the AutoLISP environment, invoking the SendStringToExecute method with no argument is invalid.
在字符串中加入回车符的 ASCII 等效值或空格等同于在键盘上按 ENTER 键。与 AutoLISP 环境不同,调用 SendCommand 方法时没有参数是无效的。
Commands executed with SendStringToExecute are asynchronous and are not invoked until the .NET command has ended. If you need to execute a command immediately (synchronously), you should:
使用 SendStringToExecute 执行命令是异步的,直到 .NET 命令结束,否则不会被调用。如果需要立即执行一个命令(同步),应该:
The following example creates a circle with a center of (2, 2, 0) and a radius of 4. The drawing is then zoomed to all the geometry in the drawing. Notice that there is a space at the end of the string which represents the final Enter to begin execution of the command.
本例创建一个圆心为(2,2,0),半径为4的圆。然后将图形缩放至图形中的所有几何图形都可见。注意,在字符串的结尾处有一个空格,表示最后一次按 ENTER 键将开始执行命令。
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
<CommandMethod("SendACommandToAutoCAD")> _
Public Sub SendACommandToAutoCAD()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
'' 绘制一个圆并缩放图形 Draws a circle and zooms to the extents or
'' limits of the drawing
acDoc.SendStringToExecute("._circle 2,2,0 4 ", True, False, False)
acDoc.SendStringToExecute("._zoom _all ", True, False, False)
End Sub
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
[CommandMethod("SendACommandToAutoCAD")]
public static void SendACommandToAutoCAD()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
// 绘制一个圆并缩放图形 Draws a circle and zooms to the extents or
// limits of the drawing
acDoc.SendStringToExecute("._circle 2,2,0 4 ", true, false, false);
acDoc.SendStringToExecute("._zoom _all ", true, false, false);
}