Pankratz
Pankratz

Reputation: 21

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

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

Upvotes: 0

Views: 9558

Answers (3)

Orem don
Orem don

Reputation: 23

Try this

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

Upvotes: 1

kaps
kaps

Reputation: 186

Explode the AcDbBlockReferance

AcDbBlockReferance.explode();

It will give u entities present in BlockReferance.

Upvotes: 1

WizzardsApprentice
WizzardsApprentice

Reputation: 447

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.

Upvotes: 1

Related Questions