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

五迷三道 提交于 2020-07-23 06:27:16

问题


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

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

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

回答1:


At first: which version of AutoCAD are you using?

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

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.




回答2:


Explode the AcDbBlockReferance

AcDbBlockReferance.explode();

It will give u entities present in BlockReferance.




回答3:


Try this

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


来源:https://stackoverflow.com/questions/3312241/how-to-i-get-the-coordinates-of-a-block-reference-in-autocad-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!