如何在 autocad-VBA 中获取块参考的坐标?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3312241/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:54:58  来源:igfitidea点击:

how to i get the coordinates of a block-reference in autocad-VBA?

vbaautocad

提问by Pankratz

I am trying to get the coordinates of an autocad blockreference.

我正在尝试获取 autocad 块引用的坐标。

With the code below I can pick a blockreference in autocad, but it always displays (0,0,0) as insertionpoint...

使用下面的代码,我可以在 autocad 中选择一个块引用,但它始终将 (0,0,0) 显示为插入点...

Is the insertionpoint the actual coordinates of a block, or not?

插入点是否是块的实际坐标?

Sub GetInsertpoint()
    Dim oEnt As AcadEntity
    Dim varPick As Variant
    Dim brBref As AcadBlockReference
    Dim arAttR As AcadAttributeReference
    Dim varAt As Variant
    Dim i As Double

    ThisDrawing.Utility.GetEntity oEnt, varPick, vbCr & "Get the block"
    If TypeOf oEnt Is AcadBlockReference Then
        MsgBox "Thank you, very nice!"
        Set brBref = oEnt
        MsgBox brBref.InsertionPoint(0) & brBref.InsertionPoint(1) & brBref.InsertionPoint(2)
    Else
        MsgBox "Not a block reference!"
        Exit Sub
    End If

End Sub

回答by WizzardsApprentice

At first: which version of AutoCAD are you using?

首先:您使用的是哪个版本的 AutoCAD?

At tried your code on a german AutoCAD 2008. I created some simple blocks from polygons and inserted them into a new drawing.

在德国 AutoCAD 2008 上尝试了您的代码。我从多边形创建了一些简单的块并将它们插入到新图形中。

When I execute your code above and select one of those blocks, I always get valid coordinates. So this might be an issue, how you created the block?

当我执行上面的代码并选择其中一个块时,我总是得到有效的坐标。所以这可能是一个问题,你是如何创建块的?

Maybe you created a block and left the "Select insertion point from screen" blank. So ACAD took the default value: (0,0,0). That would be an explanation, why you always get those coordinates.

也许您创建了一个块并将“从屏幕中选择插入点”留空。所以ACAD采用了默认值:(0,0,0)。那将是一个解释,为什么你总是得到这些坐标。

回答by kaps

Explode the AcDbBlockReferance

分解 AcDbBlockReference

AcDbBlockReferance.explode();

AcDbBlockReference.explode();

It will give u entities present in BlockReferance.

它将为您提供存在于 BlockReference 中的实体。

回答by Orem don

Try this

尝试这个

Dim point1, point2 As Variant
brBref.GetBoundingBox point1, point2
MsgBox point1(0) & " / " & point1(1) & vbcrlf & point2(0) & " / " & point2(1)