向CAD发送命令问题!
<p>Public acadApp As Object<br/>Public acadDoc As Object</p><p>Private Sub Command1_Click()<br/>On Error GoTo L:<br/> GetACDoc<br/> Dim entHandle As String<br/> Dim strcmd As String<br/> entHandle = "8E8E"<br/> acadDoc.SendCommand "LineToPline "<br/> strcmd = "(Handent""" & entHandle & """)"<br/> acadDoc.SendCommand strcmd & " " & vbCrLf<br/> acadDoc.SendCommand vbCrLf<br/> Exit Sub<br/>L:<br/> MsgBox Err.Description<br/>End Sub</p><p>'—————————————————————————————<br/>'名称:GetACDoc<br/>'作者:罗简单<br/>'日期:2009-1-13<br/>'功能:获取当前文件<br/>'—————————————————————————————<br/>Public Sub GetACDoc()<br/> '获取CASS程序和当前Document<br/> Set acadApp = GetObject(, "AutoCAD.Application")<br/> Set acadDoc = acadApp.ActiveDocument<br/>End Sub</p><p><br/>上面的代码执行到 acadDoc.SendCommand "LineToPline "<br/>时就要求在图上选择对象呢,停住了<br/>但是我<br/>strcmd = "(Handent""" & entHandle & """)"<br/>acadDoc.SendCommand strcmd & " " & vbCrLf<br/>代码就是选择对象 啊<br/>我想让直接在程序里通过句柄来选择对象,怎么解决</p><p>上面的代码如果直接在VBA里运行是可以的,但是如果用VB来调用CAD的话<br/>就要求在图上选择对象。<br/>哪位高人指点一下啊!<br/></p> 空格全部改成VbCr <p>不行啊,版主啊,我的版主我的神!</p> <p>VB好久没用了,用C#试了下,不过是用Pedit命令的</p><p>不过,由于SendCommand固有的问题,有时会出错</p><p>Com调用最好不要用SendCommand</p><p> var app = Marshal.GetActiveObject("AutoCad.Application") as AcadApplication;<br/> var doc = app.ActiveDocument;<br/> doc.SendCommand("pedit (Handent \"1F7\") Y ")</p>
页:
[1]