我正在使用AutoCAD 2013,我想从另一个文件导入块。我写了下面的代码:
Dim Zero(0 To 2) As Double
Dim i As Integer
For i = 0 To 2
Zero(i) = 0
Next i
Dim BlockRef As AcadBlockReference
FileToInsert = "D:\blocks.dwg"
Set BlockRef = ThisDrawing.ModelSpace.InsertBlock(Zero, FileToInsert, 1#, 1#, 1#, 0)
但是我收到以下错误:
Run-time error '-2145386390 (8020006a)'
No database
我发现这很奇怪,因为一周前相同的代码工作,从那以后我没有触及任何文件...... 如果我打开blocks.dwg,就会有一些块,就像它们应该的那样。
如果我注释掉这部分代码,同样的错误似乎转移到下一个
Set ... = ThisDrawing.ModelSpace. ...
我非常感谢你的帮助, Špela
答案 0 :(得分:0)
如果图形已包含块,则只需使用块名称调用InsertBlock
。像这样:
Dim exist as Boolean
exist = False
For i = 0 To ThisDrawing.Blocks.Count - 1
If StrComp(ThisDrawing.Blocks.Item(i).Name, "blocks", vbTextCompare) = 0 Then
exist = True
Exit For
End If
Next i
ThisDrawing.ModelSpace.InsertBlock(point, IIf(exist, "blocks", "D:\blocks.dwg"), 1, 1, 1, 0)