02-09 控制AutoCAD环境(九) 访问AutoCAD命令行
2011-07-13 17:16
489 查看
Access the AutoCAD Command Line访问AutoCAD命令行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环境不同,调用不带参数的SendStringToExecute方法是非法的。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命令结束,所调用的AutoCAD命令才被执行。如果需要立即执行命令(同步),我们应该:· Use the SendCommand method which is part of the COM Automation library which can be access using .NET COM Interop; 使用.NET COM互操作程序集能访问的COM Automation库的SendCommand方法;· P/Invoke the unmanaged acedCommand or acedCmd method for native AutoCAD commands and commands defined with the ObjectARX or .NET API; 对于AutoCAD本地命令及由ObjectARX或.NET API定义的命令,使用非托管的acedCommand方法或acedCmd方法;· P/Invoke the unmanaged acedInvoke method for commands defined through AutoLISP; 对于用AutoLISP定义的命令,使用非托管的acedInvoke方法;Send a command to the AutoCAD command line 发送名利到AutoCAD命令行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键开始执行命令。VB.NET Imports Autodesk.AutoCAD.ApplicationServicesImports 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 SubC# 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);}VBA/ActiveX Code Reference Sub SendACommandToAutoCAD() ' Draws a circle and zooms to the extents or ' limits of the drawing ThisDrawing.SendCommand "_Circle 2,2,0 4 " ThisDrawing.SendCommand "_zoom a "End Sub
译者:到此,《控制AutoCAD环境》这一章就翻译完了,接下来的一章是《创建和编辑AutoCAD实体(图元)》,敬请期待!
译者:到此,《控制AutoCAD环境》这一章就翻译完了,接下来的一章是《创建和编辑AutoCAD实体(图元)》,敬请期待!
相关文章推荐
- 02-02 控制AutoCAD环境(二) 控制图形窗口(4)使用平铺视口
- 02-03 控制AutoCAD环境(三) 创建、打开、保存和关闭图形
- 02-02 控制AutoCAD环境(二) 控制图形窗口(1)设置文档窗口的位置和大小
- 02-02 控制AutoCAD环境(二) 控制图形窗口(3)使用命名视图
- 02-05 控制AutoCAD环境(五) 设置AutoCAD选项
- 02-06 控制AutoCAD环境(六) 设置和返回系统变量
- 02-04 控制AutoCAD环境(四) 锁定和解锁文档
- 02-02 控制AutoCAD环境(二) 控制图形窗口(5)更新文档窗口的几何信息
- 02-01 控制AutoCAD环境(一) 控制应用程序窗口
- 02-07 控制AutoCAD环境(七) 精确制图
- 02-08 控制AutoCAD环境(八) 提示用户输入
- 02-02 控制AutoCAD环境(二) 控制图形窗口(2)缩放和平移当前视图
- UNIX环境编程学习笔记(7)——文件I/O之文件访问权限与进程访问控制
- Java随手笔记8之包、环境变量和访问控制及maven profile实现多环境打包
- 【LAMP环境搭建】配置防盗链、访问控制Directory和访问控制FilesMatch
- 面向对象篇(OOP)--02 继承、访问控制修饰符
- 红帽系统管理II 02控制对文件的访问
- 复杂网络环境下的访问控制技术
- 02_类的控制访问
- SharePoint【用户访问控制】-- 02. SharePoint 2010 用户组、权限级别、权限