wlh6226442 发表于 2009-6-25 16:37:00

[求助]VBA插入块的问题

<p>&nbsp;&nbsp;&nbsp; Dim blockRefObj As AcadBlockReference<br/>&nbsp;&nbsp;&nbsp; Dim insertionPnt(2) As Double<br/>&nbsp;&nbsp;&nbsp;&nbsp;insertionPnt(0) = 33: insertionPnt(1) = 138: insertionPnt(2) = 0<br/>&nbsp;&nbsp;&nbsp; Set blockRefObj = newdoc.ModelSpace.InsertBlock(insertionPnt, "d:\指北针.dwg", 1#, 1#, 1#, -angle)</p><p>代码如上,上面的代码在一个循环中,该循环每次都会创建一个新的CAD文件,插入一些图形后,保存,关闭。</p><p>在循环中插入上述代码后,会报错,“文件处理器错误”</p><p>郁闷的是,有时候生成每二个文件时报错,有时生成第一个就报错。不过还从来没生成成功超过两个文件。</p><p>高人指点,谢谢啦</p>

mccad 发表于 2009-6-25 20:56:00

只有上面的代码,看不出问题,能看出问题的是,在循环中重复定义变量。

wlh6226442 发表于 2009-6-25 22:33:00

<p>谢谢楼上。上面代码是在一个函数中定义的,然后在循环中调用这个函数的,所以不存在重复定义的问题。</p><p>原代码太麻烦,没法全贴,我写了一个很短的测试的代码,出的是同样的错误。</p><p>Option Explicit<br/>Public Sub newdoc()<br/>&nbsp;&nbsp;&nbsp; test ("0")<br/>&nbsp;&nbsp;&nbsp; test ("1")<br/>&nbsp;&nbsp;&nbsp; test ("2")<br/>End Sub</p><p>Private Sub test(name As String)<br/>&nbsp;&nbsp;&nbsp; Dim newdoc As AcadDocument<br/>&nbsp;&nbsp;&nbsp; Set newdoc = ThisDrawing.Application.Documents.Add("cd-road")<br/>&nbsp;&nbsp;&nbsp; Dim blockRefObj As AcadBlockReference<br/>&nbsp;&nbsp;&nbsp; Dim insertionPnt(2) As Double<br/>&nbsp;&nbsp;&nbsp; insertionPnt(0) = 33: insertionPnt(1) = 138: insertionPnt(2) = 0<br/>&nbsp;&nbsp;&nbsp; Set blockRefObj = newdoc.ModelSpace.InsertBlock(insertionPnt, "d:\指北针.dwg", 1#, 1#, 1#, 0)<br/>&nbsp;&nbsp;&nbsp; newdoc.SaveAs ThisDrawing.Path &amp; "\" &amp; name<br/>&nbsp;&nbsp;&nbsp; newdoc.Close<br/>End Sub<br/>&nbsp;&nbsp;&nbsp; </p><p>麻烦各位高手帮忙再看看。</p>

wlh6226442 发表于 2009-6-26 15:43:00

<p>谁帮忙再看看哈</p>

sailorcwx 发表于 2009-6-26 18:54:00

<p>看看</p>

雪山飞狐_lzh 发表于 2009-6-27 23:08:00

试下ObjectDbx吧

woaishuijia 发表于 2009-6-28 07:23:00

<p>Option Explicit<br/>&nbsp;&nbsp;&nbsp; Dim D As New AxDbDocument<br/>&nbsp;&nbsp;&nbsp; Dim blockRefObjs(0) As AcadBlockReference</p><p>Sub newdoc()<br/>&nbsp;&nbsp;&nbsp; Dim insertionPnt(2) As Double<br/>&nbsp;&nbsp;&nbsp; insertionPnt(0) = 33: insertionPnt(1) = 138: insertionPnt(2) = 0<br/>&nbsp;&nbsp;&nbsp; On Error Resume Next<br/>&nbsp;&nbsp;&nbsp; Set blockRefObjs(0) = D.ModelSpace.InsertBlock(insertionPnt, "d:\指北针.dwg", 1#, 1#, 1#, 0)<br/>&nbsp;&nbsp;&nbsp; test ("0")<br/>&nbsp;&nbsp;&nbsp; test ("1")<br/>&nbsp;&nbsp;&nbsp; test ("2")<br/>End Sub</p><p>Private Sub test(name As String)<br/>&nbsp;&nbsp;&nbsp; Dim newdoc As New AcadDocument<br/>&nbsp;&nbsp;&nbsp; D.CopyObjects blockRefObjs, newdoc.ModelSpace<br/>&nbsp;&nbsp;&nbsp; newdoc.Close True, ThisDrawing.Path &amp; "\" &amp; name<br/>End Sub</p>
页: [1]
查看完整版本: [求助]VBA插入块的问题