Results 1 to 6 of 6

Thread: How can I select last object

  1. #1
    Active Member
    Join Date
    2005-02
    Posts
    95
    Login to Give a bone
    0

    Default How can I select last object

    I have written program for selecting object but now I want to select last object automatically.

    Is it down code is writeen is ok or some change in the Code.



    Set LastObj = ThisDrawing.SelectionSets.Add(Count - 1)


    pixlepark96@sancharnet.in

  2. #2
    All AUGI, all the time
    Join Date
    2015-12
    Location
    Central Oregon
    Posts
    591
    Login to Give a bone
    0

    Default Re: How can I select last object

    This will return the Last created object in the drawing, not necessarily the last item in the current layout.
    Code:
    Function LastObject() As AcadEntity
    Dim oLayout As AcadLayout
    Dim sLast As String
    Dim sHandle As String
    
    For Each oLayout In ThisDrawing.Layouts
        If oLayout.Block.Count > 0 Then
            sHandle = oLayout.Block.Item(oLayout.Block.Count - 1).Handle
            If CLng("&H" & sHandle) > CLng("&H" & sLast) Then sLast = sHandle
        End If
    Next
    
    If sLast > "" Then Set LastObject = ThisDrawing.HandleToObject(sLast)
        
    End Function
    HTH
    Jeff
    Last edited by Jeff_M; 2006-04-06 at 04:42 PM.

  3. #3
    Active Member
    Join Date
    2005-02
    Posts
    95
    Login to Give a bone
    0

    Default Re: How can I select last object

    Thanx

    but in my object selection is not a block. I am selecting any last object

  4. #4
    Active Member
    Join Date
    2002-06
    Location
    Portland, OR
    Posts
    83
    Login to Give a bone
    0

    Default Re: How can I select last object

    Try this-

    Code:
    Sub PickLast()
    
      Dim ss As AcadSelectionSet
      
      Set ss = ThisDrawing.SelectionSets.Add(Now)
      
      ss.Select acSelectionSetLast
      
    ;...your code here...
      
    End Sub
    hope this helps. Of course you will want to add your own code on to this, but I think that this is what you need.

    Cheers

  5. #5
    Active Member
    Join Date
    2005-02
    Posts
    95
    Login to Give a bone
    0

    Default Re: How can I select last object

    Thanx for Reply

  6. #6
    All AUGI, all the time
    Join Date
    2015-12
    Location
    Central Oregon
    Posts
    591
    Login to Give a bone
    0

    Default Re: How can I select last object

    Quote Originally Posted by avinash00002002
    Thanx

    but in my object selection is not a block. I am selecting any last object
    HUH? All the code I posted does is search each Layout and get the most recently added object from each one and compares it to the previous one found. If the current one found is newer than the previous then it gets saved. This repeats until all layouts have been queried and the most recently added entity to the drawing is returned.

Similar Threads

  1. Select Object: last was changed
    By rick.rivera in forum ACA General
    Replies: 0
    Last Post: 2007-06-25, 04:06 PM
  2. Select Object first then run command, nothing happens.
    By amarkovi in forum AutoCAD General
    Replies: 3
    Last Post: 2006-09-14, 12:15 PM
  3. Unable to select an OLE Object
    By fishervb in forum AutoCAD General
    Replies: 4
    Last Post: 2006-05-31, 02:36 PM
  4. Unable to select more than one Object?
    By jgh in forum AutoCAD General
    Replies: 2
    Last Post: 2005-12-19, 04:28 PM
  5. Replies: 3
    Last Post: 2004-06-14, 06:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •