AndyliuCAD 发表于 2010-5-14 18:27:00

向CAD发送命令问题!

<p>Public acadApp As Object<br/>Public acadDoc As Object</p><p>Private Sub Command1_Click()<br/>On Error GoTo L:<br/>&nbsp; GetACDoc<br/>&nbsp; Dim entHandle As String<br/>&nbsp; Dim strcmd As String<br/>&nbsp;&nbsp;&nbsp; entHandle = "8E8E"<br/>&nbsp;&nbsp;&nbsp; acadDoc.SendCommand "LineToPline "<br/>&nbsp;&nbsp;&nbsp; strcmd = "(Handent""" &amp; entHandle &amp; """)"<br/>&nbsp;&nbsp;&nbsp; acadDoc.SendCommand strcmd &amp; " " &amp; vbCrLf<br/>&nbsp;&nbsp;&nbsp; acadDoc.SendCommand vbCrLf<br/>&nbsp; Exit Sub<br/>L:<br/>&nbsp; MsgBox Err.Description<br/>End Sub</p><p>'—————————————————————————————<br/>'名称:GetACDoc<br/>'作者:罗简单<br/>'日期:2009-1-13<br/>'功能:获取当前文件<br/>'—————————————————————————————<br/>Public Sub GetACDoc()<br/>&nbsp; '获取CASS程序和当前Document<br/>&nbsp; Set acadApp = GetObject(, "AutoCAD.Application")<br/>&nbsp; Set acadDoc = acadApp.ActiveDocument<br/>End Sub</p><p><br/>上面的代码执行到 acadDoc.SendCommand "LineToPline "<br/>时就要求在图上选择对象呢,停住了<br/>但是我<br/>strcmd = "(Handent""" &amp; entHandle &amp; """)"<br/>acadDoc.SendCommand strcmd &amp; " " &amp; vbCrLf<br/>代码就是选择对象 啊<br/>我想让直接在程序里通过句柄来选择对象,怎么解决</p><p>上面的代码如果直接在VBA里运行是可以的,但是如果用VB来调用CAD的话<br/>就要求在图上选择对象。<br/>哪位高人指点一下啊!<br/></p>

雪山飞狐_lzh 发表于 2010-5-15 00:00:00

空格全部改成VbCr

AndyliuCAD 发表于 2010-5-17 08:32:00

<p>不行啊,版主啊,我的版主我的神!</p>

雪山飞狐_lzh 发表于 2010-5-17 13:19:00

<p>VB好久没用了,用C#试了下,不过是用Pedit命令的</p><p>不过,由于SendCommand固有的问题,有时会出错</p><p>Com调用最好不要用SendCommand</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var app = Marshal.GetActiveObject("AutoCad.Application") as AcadApplication;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var doc = app.ActiveDocument;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; doc.SendCommand("pedit (Handent \"1F7\") Y&nbsp; ")</p>
页: [1]
查看完整版本: 向CAD发送命令问题!