Get Last Entity

Get Last Entity

ChrisPicklesimer
Advocate Advocate
5,129 Views
6 Replies
Message 1 of 7

Get Last Entity

ChrisPicklesimer
Advocate
Advocate

Could someone point me in the direction of how to get the last entity created in a drawing? 

 

In VBA, I did it this way:

 

Public Function entLast(Optional Layout As String = "Model", Optional Index As Long = 1) As AcadObject

    Dim blk As AcadBlock

    Set blk = ThisDrawing.Layouts(Layout).Block
    Set entLast = blk.Item(blk.count - Index)

End Function

 

Thanks.

 

Chris

0 Likes
5,130 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

Depends on whether you want the last entity in the drawing that

was created by your code, or the last entity regardless of what

created it.

 

0 Likes
Message 3 of 7

Anonymous
Not applicable

AcMgd.dll has Autodesk.AutoCAD.Internal.Utils.EntLast() which returns an ObjectID.

At least 2011 has it. Not sure about previous versions.

 

Message 4 of 7

ChrisPicklesimer
Advocate
Advocate

In this case, it would be the last entity regardless of how created.  However, I'm now curious how to do both.

 

Thanks.

 

Chris

0 Likes
Message 5 of 7

ChrisPicklesimer
Advocate
Advocate

I'm currently in 2010 and it appears it is in the lineup.  I'll check it out.

 

Thanks for the help.

 

Chris

0 Likes
Message 6 of 7

Anonymous
Not applicable

acdbEntLast() returns the last entity created in any space.

 

If you want the last entity created in the current space,

you can use the Editor's SelectLast() method.

 

 

0 Likes
Message 7 of 7

ChrisPicklesimer
Advocate
Advocate

Thanks again for the clarification.

 

Chris

0 Likes