EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 636|回复: 0
打印 上一主题 下一主题

[资料] 控制AutoCAD环境(九) 访问AutoCAD命令行

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10

积分
12404

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-8 15:51:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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.NETImports Autodesk.AutoCAD.ApplicationServices
  1. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><strong></strong></div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Imports Autodesk.AutoCAD.Runtime</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><CommandMethod("SendACommandToAutoCAD")> _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Public Sub SendACommandToAutoCAD()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  '' Draws a circle and zooms to the extents or</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  '' limits of the drawing</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  acDoc.SendStringToExecute("._circle 2,2,0 4 ", True, False, False)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  acDoc.SendStringToExecute("._zoom _all ", True, False, False)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">End Sub</div>
复制代码
C#using Autodesk.AutoCAD.ApplicationServices;
  1. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><strong></strong></div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.Runtime;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">[CommandMethod("SendACommandToAutoCAD")]</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">public static void SendACommandToAutoCAD()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">{</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Document acDoc = Application.DocumentManager.MdiActiveDocument;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  // Draws a circle and zooms to the extents or limits of the drawing</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  //画圆并缩放到图形界限</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  acDoc.SendStringToExecute("._circle 2,2,0 4 ", true, false, false);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  acDoc.SendStringToExecute("._zoom _all ", true, false, false);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">}</div>
复制代码
VBA/ActiveX Code ReferenceSub SendACommandToAutoCAD()
  1. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><strong></strong></div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">   ' Draws a circle and zooms to the extents or</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">   ' limits of the drawing</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">   ThisDrawing.SendCommand "_Circle 2,2,0 4 "</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">   ThisDrawing.SendCommand "_zoom a "</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">End Sub</div>
复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对

相关帖子

工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-16 13:01

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表