Autocad 2011 vba 和外部参照
我使用这个在另一个文件中插入外部 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不明白为什么你不开始使用 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 !