Last entity created in drawing?

Discussion in 'AutoCAD' started by jwilkerson, Mar 3, 2005.

  1. jwilkerson

    jwilkerson Guest

    I want to return the last entity created in a drawing. I was thinking to use handles somehow. Are handle created in increasing order?
     
    jwilkerson, Mar 3, 2005
    #1
  2. How about the last entity created in model space
    or a paper space layout?

    If so, just get the last element in the appropriate
    collection (using .Count - 1 as the index).
     
    Tony Tanzillo, Mar 3, 2005
    #2
  3. jwilkerson

    Paul Turvill Guest

    (entlast)
    ___
     
    Paul Turvill, Mar 3, 2005
    #3
  4. jwilkerson

    James Buzbee Guest

    Option Explicit
    WOW! Now I know VBA is better than lisp! And all this time I've been using
    (entlast) . . . ;-)

    jb
     
    James Buzbee, Mar 3, 2005
    #4
  5. jwilkerson

    Jeff Mishler Guest

    Just to show that I learn from my posts here, Thanks Tony!, here's something
    that works pretty well for me.
    First a lisp function is required to be defined in the current drawing:
    *************
    (defun *entlast* ()
    (cdr (assoc 5 (entget (entlast))))
    )
    *************
    Then the VBA function:
    *************
    Public Function entLast() As AcadEntity
    Dim vl As Object
    Dim vlFun As Object
    Dim Result As String

    Set vl = ThisDrawing.Application.GetInterfaceObject("VL.Application.1")
    Set vlFun = vl.ActiveDocument.Functions
    Result = vlFun.Item("*entlast*")
    Set entLast = ThisDrawing.HandleToObject(Result)

    End Function
    ************
    And to test it:
    ************
    Sub testme()
    Dim ent As AcadEntity

    Set ent = entLast
    Debug.Print ent.ObjectName
    End Sub
     
    Jeff Mishler, Mar 4, 2005
    #5
  6. jwilkerson

    Jeff Mishler Guest

    And to eliminate the need for a seperate lisp that must be loaded:

    Public Function entLast() As AcadEntity
    Dim vl As Object
    Dim vlFun As Object
    Dim Result As String

    Set vl = ThisDrawing.Application.GetInterfaceObject("VL.Application.1")
    Set vlFun = vl.ActiveDocument.Functions
    On Error GoTo err_Here
    Result = vlFun.Item("*jmm:entlast*")
    GoTo exit_Here

    err_Here:
    Select Case Err.Number
    Case Is = 2000
    ThisDrawing.SendCommand "(defun *jmm:entlast* ()(cdr (assoc 5
    (entget (entlast))))) "
    Resume
    Case Else
    Set entLast = Nothing
    Exit Function
    End Select

    exit_Here:
    Set entLast = ThisDrawing.HandleToObject(Result)

    End Function
     
    Jeff Mishler, Mar 4, 2005
    #6
  7. Tony has the right idea.

    Dim oEnt as AcadEntity
    Set oEnt = ThisDrawing.ModelSpace(ThisDrawing.ModelSpace.Count - 1)
    ' (for ModelSpace)


     
    Mark Johnston, Mar 5, 2005
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.