我怀疑Dave想先检查BlockTableRecord是否存在,如果不存在,则从文件中插入它(正如在SFSP中发现的那样)。。。我的VBA几乎不存在(我只在LISP/.NET中编写代码),因此可以从中学习:
- Dim dwg As String
- dwg = "Tri"
- Dim BlockToCheck As AcadBlock
- Dim BlockRefObj As AcadBlockReference
- On Error Resume Next
- Set BlockToCheck = ThisDrawing.Blocks.Item(dwg)
- On Error Resume Next
- If BlockToCheck Is Nothing Then
- dwg$ = [color="red"]AcadFindFile[/color](dwg)
- End If
- Set BlockRefObj = ThisDrawing.ModelSpace.InsertBlock(TriPos, dwg, CScale, CScale, CScale, 0)
... 以及依赖的AcadFindFile()伪函数:
- Function AcadFindFile(fname As String) As String
- Dim envpath As Variant, i As Integer, FSO As FileSystemObject, srchfname As String
- envpath = Split(Application.ActiveDocument.GetVariable("Acadprefix"), ";")
- Set FSO = New FileSystemObject
- For i = LBound(envpath) To UBound(envpath)
- srchfname = FSO.BuildPath(envpath(i), fname)
- If FSO.FileExists(srchfname) Then
- AcadFindFile = srchfname
- Exit For
- End If
- Next
- End Function
|