zdm860114 发表于 2009-3-14 12:03:00

[求助]请高手看看,关于VB调用AutoCAD的,总有错语

<p>代码如下,请各位大哥们看看,最后一句总有问题</p><p>初学这个,不太懂,请各位指教指教!在此谢过!</p><p>Dim Acsdapp As AcadApplication<br/>Private Sub Form_Load()<br/>On Error Resume Next<br/>Set AcadApp = GetObject(, "autocad.application")<br/>If Err Then<br/>&nbsp;&nbsp; Err.Clear<br/>&nbsp;&nbsp; Set AcadApp = CreateObject("autocad.application")<br/>If Err Then<br/>&nbsp;&nbsp; MsgBox ("不能运行AutoCAD")<br/>&nbsp;&nbsp; Exit Sub<br/>&nbsp;&nbsp; End If<br/>End If<br/>AcadApp.Visible = Ture<br/>End Sub</p><p>Private Sub Command1_Click()<br/>Dim a, b As Single<br/>Dim lineobj As AcadLWPolyline<br/>Dim points(0 To 9) As Double<br/>a = Val(Text1.Text)<br/>b = Val(Text2.Text)<br/>points(0) = 0: points(1) = 0<br/>points(2) = points(0) + a: points(3) = points(1)<br/>points(4) = points(2): points(5) = points(3) + b<br/>points(6) = points(0): points(7) = points(5)<br/>points(8) = points(0): points(9) = points(1)<br/>Set lineobj = AcadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(points)<br/>ZoomAll<br/>End Sub</p>

Saging 发表于 2009-3-14 12:52:00

<p>ZoomAll?????</p><p>是不是漏了什么???</p>

zdm860114 发表于 2009-3-14 14:45:00

<p>我也不太明白,反正到</p><p>Set lineobj = AcadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(points)<br/>这一句就出问题了</p><p>大家帮我看看啊,到底是那里出问题了</p><p>不胜感激!</p>

兰州人 发表于 2009-3-14 21:29:00

<p>这是VB模块调用的概念问题,首先要学点VB知识。你执行这个语句,</p><p>用F9将这条语句中断,</p><p>Set lineobj = AcadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(points)</p><p>在本地窗口中看AcadApp是不是为Nothing,学点VB这个问题很容易解决。</p><p><br/></p>

Saging 发表于 2009-3-24 15:57:00

<p>&nbsp;&nbsp;&nbsp; Private Sub Command1_Click()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim a, b As Single<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim lineobj As AutoCAD.AcadLWPolyline<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim points(9) As Double</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Acadapp = GetObject(, "autocad.application")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Err.Number Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Err.Clear()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Acadapp = CreateObject("autocad.application")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Err.Number Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox("不能运行AutoCAD")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Acadapp.Visible = True<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = Val(TextBox1.Text)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = Val(TextBox2.Text)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; points(0) = 0 : points(1) = 0<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; points(2) = points(0) + a : points(3) = points(1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; points(4) = points(2) : points(5) = points(3) + b<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; points(6) = points(0) : points(7) = points(5)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; points(8) = points(0) : points(9) = points(1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lineobj = Acadapp.ActiveDocument.ModelSpace.AddLightWeightPolyline(points)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Acadapp.ZoomAll()<br/>&nbsp;&nbsp;&nbsp; End Sub</p><p></p><p>在VB.NET 2003中调试通过.</p>

zzyong00 发表于 2009-3-24 16:36:00

zdm860114发表于2009-3-14 14:45:00static/image/common/back.gif我也不太明白,反正到Set lineobj = AcadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(points)这一句就出问题了大家帮我看看啊,到底是那里出问题了不胜感激!

<p>&nbsp;问问题,要问的明白,才能回答的明白,“出问题了”,出什么问题了?错误提示是什么?你没给出来,在我看来,哪代码没什么问题</p>

pmq 发表于 2009-3-25 10:59:00

<p>Dim <font color="#ee1196">Acsdapp</font> As AcadApplication&nbsp;&nbsp; <font color="#11ee11">应为</font><font color="#f73809">Acadapp</font><br/>Private Sub Form_Load()<br/>On Error Resume Next<br/>Set AcadApp = GetObject(, "autocad.application")<br/>If Err Then<br/>&nbsp;&nbsp; Err.Clear<br/>&nbsp;&nbsp; Set AcadApp = CreateObject("autocad.application")<br/>If Err Then<br/>&nbsp;&nbsp; MsgBox ("不能运行AutoCAD")<br/>&nbsp;&nbsp; Exit Sub<br/>&nbsp;&nbsp; End If<br/>End If<br/>AcadApp.Visible = Ture<br/>End Sub</p>

AirCD 发表于 2009-4-24 17:10:00

<p>呵呵,居然是代码敲错了,楼主该好好检查啊。犯这种错误不大应该。</p>

votasee 发表于 2009-7-22 14:35:00

<p>还是这里好啊...</p><p>我最近也开始学习VB开发CAD.结果却一懂不懂!</p><p>下面这段代码引自帮助文件上的示例代码..</p><pre class="Code">Sub Example_AddCircle()<br/>&nbsp;&nbsp;&nbsp; ' 该示例在模型空间中创建圆。<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim circleObj As AcadCircle<br/>&nbsp;&nbsp;&nbsp; Dim centerPoint(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; Dim radius As Double<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' 定义圆<br/>&nbsp;&nbsp;&nbsp; centerPoint(0) = 0#: centerPoint(1) = 0#: centerPoint(2) = 0#<br/>&nbsp;&nbsp;&nbsp; radius = 5#<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' 在模型空间中创建圆对象<br/>&nbsp;&nbsp;&nbsp; Set circleObj = ThisDrawing.ModelSpace.AddCircle(centerPoint, radius)<br/>&nbsp;&nbsp;&nbsp; ZoomAll<br/>&nbsp;&nbsp;&nbsp; <br/>End Sub</pre><pre class="Code"></pre><pre class="Code">结果却弄死也不对.楼主的程序我拿来一用.却对了.哈哈...</pre><pre class="Code">原来这个THISdrawing..要改为Acadapp.Activedocumnet汗...<br/></pre>

syk070205 发表于 2010-8-3 11:42:00

对了,Acadapp = GetObject(, "autocad.application"),这一句应该为:set Acadapp = GetObject(, "autocad.application"),否则你创建的应用程序对象无效!<br/>
页: [1]
查看完整版本: [求助]请高手看看,关于VB调用AutoCAD的,总有错语