Autocad 2011 vba 和外部参照

发布于 2024-10-04 09:59:25 字数 1344 浏览 2 评论 0原文

我使用这个在另一个文件中插入外部 dwg 文件:

Set xrefInserted = ThisDrawing.ModelSpace.AttachExternalReference(refDwgName, refDwgName, insertionPnt, 1, 1, 1, 0, False)
xrefInserted.Update

这是作为外部块插入的,因此我将其绑定到我的绘图:

        For Each tempBlock In ThisDrawing.Blocks
           If tempBlock.IsXRef Then
               If (InStr(1, UCase(tempBlock.name), "MAJ_MATRICE", vbTextCompare)) Then
                    tempBlock.Bind (False)
                   Exit For
               End If
            End If
        Next

现在我想分解它,首先 AcadBlock 似乎没有分解方法,只有 AcadBlockReference 。

所以我寻找参考:

Dim ent As AcadEntity
Dim blockRefObj As AcadBlockReference

    For Each ent In ThisDrawing.ModelSpace
       If TypeOf ent Is AcadBlockReference Then
           If (InStr(1, UCase(ent.name), "MAJ_MATRICE", vbTextCompare)) Then
                Set blockRefObj = ent
                blockRefObj.Explode
                Exit For
           End If
       End If
    Next

问题是

blockRefObj.Explode

失败,它告诉我“无效 -2145386494”。

我调试了代码,我相信问题是因为 AcadBlockReference 仍然是 AcadExternalReference 类型,并且不可能分解外部引用。

如果我在返回绘图(函数调用已结束)后重新运行代码并查找 AcadBlockReference,它现在是 AcadBlockReference 类型,我可以正确分解它。

我似乎无法在绑定它的同一函数、同一执行中执行此操作。

I am inserting an external dwg file in another one using this:

Set xrefInserted = ThisDrawing.ModelSpace.AttachExternalReference(refDwgName, refDwgName, insertionPnt, 1, 1, 1, 0, False)
xrefInserted.Update

This is inserted as a external block, so I bind it to my drawing:

        For Each tempBlock In ThisDrawing.Blocks
           If tempBlock.IsXRef Then
               If (InStr(1, UCase(tempBlock.name), "MAJ_MATRICE", vbTextCompare)) Then
                    tempBlock.Bind (False)
                   Exit For
               End If
            End If
        Next

Now I want to explode it, first thing AcadBlock does not seem to have and explode method, only AcadBlockReference.

So I look for the reference:

Dim ent As AcadEntity
Dim blockRefObj As AcadBlockReference

    For Each ent In ThisDrawing.ModelSpace
       If TypeOf ent Is AcadBlockReference Then
           If (InStr(1, UCase(ent.name), "MAJ_MATRICE", vbTextCompare)) Then
                Set blockRefObj = ent
                blockRefObj.Explode
                Exit For
           End If
       End If
    Next

The problem, is

blockRefObj.Explode

fails it tells me "Not valid -2145386494".

I debugged the code and I beleive the problem is because the AcadBlockReference is still of type AcadExternalReference and it is not possible to explode a external reference.

If I rerun the code after I am taken back to the drawing (the function call has ended) and I look for the AcadBlockReference, it is now of type AcadBlockReference and I can correctly explode it.

I just can't seem to be able to do it in the same function, in the same execution as binding it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

今天小雨转甜 2024-10-11 09:59:25

我不明白为什么你不开始使用 thisdrawing.modelspace.insertblock ?
这首先返回一个 acadblockreference 对象!

I fail to see why you wouldn't start off by using thisdrawing.modelspace.insertblock ?
This returns an acadblockreference object in the first place !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文