Results 1 to 3 of 3

Thread: sort list with extra

  1. #1
    Member
    Join Date
    2009-01
    Location
    New Jersey
    Posts
    32
    Login to Give a bone
    0

    Default sort list with extra

    hello i posted a couple weeks ago about how to sort a list and got awesome responses as to how. i am trying to sort a list that looks like this
    Code:
    (
    (("PANEL-MARK" "E-102")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-101")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-104")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-102")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-102b")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-103")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-102a")("Qty" 1) (1917.09 839.649 0.0)) 
    )
    i need to sort is by the "E-###" place so the (cadr (assoc "PANEL-MARK")) the issue is that some of the marks will have a character after them like a b c d and i need it to sort the list by this character too if it does have it or atleast group them all together. my list is getting sorted like this..
    Code:
    (
    (("PANEL-MARK" "E-101")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-102")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-102b")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-102a")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-102")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-103")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-104")("Qty" 1) (1917.09 839.649 0.0)) 
    )
    where the E-102's are the issue. any way to fix this to come out in order? 102 102a 102b or at least maybe group the 102's together?
    Last edited by Opie; 2009-03-13 at 05:06 PM. Reason: [code] tags added

  2. #2
    Active Member
    Join Date
    2002-12
    Posts
    77
    Login to Give a bone
    0

    Default Re: sort list with extra

    You may need to use:

    chr and ascii along with strcase to sort beyond what you have now.

    also take a look at:

    (vl-string->list string)

    This gives you a list of ascii numbers from the string provided. Check the length of that list then sort the list, group the list by number then check the last element in the list for ascending order and sort that group.

  3. #3
    I could stop if I wanted to
    Join Date
    2005-09
    Location
    Canada
    Posts
    214
    Login to Give a bone
    0

    Default Re: sort list with extra

    Code:
    (setq List1 '(
    (("PANEL-MARK" "E-102")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-101")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-104")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-102")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-102b")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-103")("Qty" 1) (1917.09 839.649 0.0)) 
    (("PANEL-MARK" "E-102a")("Qty" 1) (1917.09 839.649 0.0)) 
    ))
    
    
    (defun SORTLIST1 (MyList / List2)
    (setq List2 nil)
    (foreach n MyList
      (setq List2 (append List2 (list (cadar n))))
    )
    (setq List2 (vl-sort List2 '<))
    (setq NewList nil)
    (foreach n List2
      (foreach i MyList
        (if (eq n (cadar i))
          (setq NewList (append NewList (list i)))
        )
      )
    )
    NewList
    )
    (SORTLIST1 List1)
    

Similar Threads

  1. Sort Filter List
    By Wish List System in forum Revit Architecture - Wish List
    Replies: 0
    Last Post: 2014-08-28, 01:52 PM
  2. help me to vl-sort this list
    By Serhan_BAKIR in forum AutoLISP
    Replies: 15
    Last Post: 2013-06-14, 01:25 PM
  3. Parcels Properties Analysis list extra segments?
    By fairhilleng in forum AutoCAD Civil 3D - Parcels
    Replies: 4
    Last Post: 2009-05-07, 06:29 PM
  4. sort list
    By parkerfeldman in forum AutoLISP
    Replies: 1
    Last Post: 2009-02-20, 10:19 PM
  5. Sort list of numbers
    By avinash00002002 in forum VBA/COM Interop
    Replies: 3
    Last Post: 2006-03-27, 05:21 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
  •