[求助]VBA插入块的问题
<p> Dim blockRefObj As AcadBlockReference<br/> Dim insertionPnt(2) As Double<br/> insertionPnt(0) = 33: insertionPnt(1) = 138: insertionPnt(2) = 0<br/> Set blockRefObj = newdoc.ModelSpace.InsertBlock(insertionPnt, "d:\指北针.dwg", 1#, 1#, 1#, -angle)</p><p>代码如上,上面的代码在一个循环中,该循环每次都会创建一个新的CAD文件,插入一些图形后,保存,关闭。</p><p>在循环中插入上述代码后,会报错,“文件处理器错误”</p><p>郁闷的是,有时候生成每二个文件时报错,有时生成第一个就报错。不过还从来没生成成功超过两个文件。</p><p>高人指点,谢谢啦</p> 只有上面的代码,看不出问题,能看出问题的是,在循环中重复定义变量。 <p>谢谢楼上。上面代码是在一个函数中定义的,然后在循环中调用这个函数的,所以不存在重复定义的问题。</p><p>原代码太麻烦,没法全贴,我写了一个很短的测试的代码,出的是同样的错误。</p><p>Option Explicit<br/>Public Sub newdoc()<br/> test ("0")<br/> test ("1")<br/> test ("2")<br/>End Sub</p><p>Private Sub test(name As String)<br/> Dim newdoc As AcadDocument<br/> Set newdoc = ThisDrawing.Application.Documents.Add("cd-road")<br/> Dim blockRefObj As AcadBlockReference<br/> Dim insertionPnt(2) As Double<br/> insertionPnt(0) = 33: insertionPnt(1) = 138: insertionPnt(2) = 0<br/> Set blockRefObj = newdoc.ModelSpace.InsertBlock(insertionPnt, "d:\指北针.dwg", 1#, 1#, 1#, 0)<br/> newdoc.SaveAs ThisDrawing.Path & "\" & name<br/> newdoc.Close<br/>End Sub<br/> </p><p>麻烦各位高手帮忙再看看。</p> <p>谁帮忙再看看哈</p> <p>看看</p> 试下ObjectDbx吧 <p>Option Explicit<br/> Dim D As New AxDbDocument<br/> Dim blockRefObjs(0) As AcadBlockReference</p><p>Sub newdoc()<br/> Dim insertionPnt(2) As Double<br/> insertionPnt(0) = 33: insertionPnt(1) = 138: insertionPnt(2) = 0<br/> On Error Resume Next<br/> Set blockRefObjs(0) = D.ModelSpace.InsertBlock(insertionPnt, "d:\指北针.dwg", 1#, 1#, 1#, 0)<br/> test ("0")<br/> test ("1")<br/> test ("2")<br/>End Sub</p><p>Private Sub test(name As String)<br/> Dim newdoc As New AcadDocument<br/> D.CopyObjects blockRefObjs, newdoc.ModelSpace<br/> newdoc.Close True, ThisDrawing.Path & "\" & name<br/>End Sub</p>
页:
[1]