Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Sorting a list of that contains a list of alphanumeric room numbers

  1. #11
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Sorting a list of that contains a list of alphanumeric room numbers

    No bug, just one of those pesky potentialities I mentioned earlier. Haha

    I only accounted for the data set provided, and you most recent data set introduces CONDitions that were not accounted for; Glad you got it sorted... Although, you now have duplicate test expressions, and some of your SUBSTR calls may return undesired results.


    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  2. #12
    Member
    Join Date
    2013-07
    Posts
    20
    Login to Give a bone
    0

    Default Re: Sorting a list of that contains a list of alphanumeric room numbers

    maybe I am just not seeing it, but I don't see the duplicate conditions. I do see duplicate Add_ substr and I think in my latest version it is this

    (cond
    ((or (wcmatch n "###") (wcmatch n "@##"))
    (_Add "*" n "*")
    )
    ((wcmatch n "@###")
    (_Add (substr n 1 1) (substr n 2) "*")
    )
    ((or (wcmatch n "@###@") (wcmatch n "@###@@") (wcmatch n "@###@@@") (wcmatch n "@@##") (wcmatch n "@@##@") (wcmatch n "@@##@@") (wcmatch n "@@##@@@"))
    (_Add (substr n 1 1) (substr n 2 3) (substr n 5))
    )
    ((or (wcmatch n "@###@") (wcmatch n "@###@@") (wcmatch n "@###@@@") (wcmatch n "@@##@") (wcmatch n "@@##@@") (wcmatch n "@@##@@@"))
    (_Add (substr n 1 1) (substr n 2 3) (substr n 5))
    )
    ((or (wcmatch n "###@") (wcmatch n "###@@") (wcmatch n "###@@@") (wcmatch n "@##@") (wcmatch n "@##@@") (wcmatch n "@##@@@"))
    (_Add "*" (substr n 1 3) (substr n 4))
    )
    (T (_Add "*" n "*")) ;need to do this if all conditions above are not met, so room numbers do not get deleted
    )
    Last edited by frisbee; 2017-11-23 at 03:54 PM.

  3. #13
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: Sorting a list of that contains a list of alphanumeric room numbers

    The breaking up of the strings and sorting them individually and recombining them is a good trick.

    Below is an example of my good coding practices (most should be able to understand the program)

    I have trouble reading spaghetti code, or code with short variables names or without headers and notes.

    But that is just me.

    P=

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Written By: Peter Jamtgaard C.E., P.E., S.E. copyright 2017 All Rights Reserved
    ;___________________________________________________________________________________________________________|
    ;
    ; Abstract: Function to sort a list of room numbers like "A101B" or "101C"
    ; Syntax:   (RoomNumberSort lstRoomNumberStrings)
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Command Line Functions
    ;___________________________________________________________________________________________________________|
    
    ;* C:TestRoom
    ;* Function to test sort for supplied room numbers
    
    ;___________________________________________________________________________________________________________|
    ;
    ; General Function Header List 
    ;___________________________________________________________________________________________________________|
    
    ;  Function, Arguments and Description
    
    ;* (IsAsciiNumeral intAscii)
    ;* Function to check is string character is a numeral
    
    ;* (RoomNumberParse strRoomNumber)
    ;* Function to parse a string (roomnumber) and separate letters and numerals in groups and return a list.
    
    ;* (RoomNumberSort lstRoomNumbers)
    ;* Function to sort list of room numbers
    
    ;* (SortListofSublistsbyItem lstOfSublists intItem)
    ;* Function to sort a list of sublists by Item
    
    ;* (SublistsEqualLength lstOfSublists)
    ;* Function to check the length of each sublist in a list of sublists
    
    ;$ Header End
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to test sort for supplied room numbers
    ;___________________________________________________________________________________________________________|
    
    (defun C:TestRoom ()
     (roomnumbersort 
        '(("101") ("102")
         ("A101") ("105") 
         ("104") ("104A") 
         ("104AB") ("104AA") 
         ("A104") ("A104A") 
         ("107") ("A105")) 
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to check is string character is a numeral
    ;___________________________________________________________________________________________________________|
    
    
    (defun IsAsciiNumeral (intAscii)(<= 48 intAscii 57))
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to parse a string (roomnumber) and separate letters and numerals in groups and return a list.
    ;___________________________________________________________________________________________________________|
    
    (defun RoomNumberParse (strRoomNumber / intAsciiOld intAsciiOld lstOfRoomNumber lstRoomNumber2 lstSublist)
     (if (= (type strRoomNumber) 'LIST)
      (setq strRoomNumber (car strRoomNumber))
     )
     (foreach intAscii (vl-string->list strRoomNumber)
      (or (and (= (IsAsciiNumeral intAscii)
                  (IsAsciiNumeral intAsciiOld)    
               )
               (setq lstSublist  (cons intAscii lstSublist))
          )
          (and (setq lstOfRoomNumber (cons (reverse lstSublist) lstOfRoomNumber))
               (setq lstSublist (list intAscii))
          )      
      ) 
      (setq intAsciiOld intAscii)
     )
     (setq lstOfRoomNumber (cons (reverse lstSublist) lstOfRoomNumber))
     (mapcar 'vl-list->string (reverse lstOfRoomNumber))
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to sort list of room numbers
    ;___________________________________________________________________________________________________________|
    
    (defun RoomNumberSort (lstRoomNumbers / blnLists lstOfRoomNumbers)
     (if (= (type (car lstRoomNumbers)) 'LIST) (setq lstRoomNumbers (mapcar 'car lstRoomNumbers) blnLists T))
     (if (and (setq lstofRoomNumbers (mapcar 'RoomNumberParse  lstRoomNumbers))
              (setq lstOfRoomNumbers (SublistsEqualLength      lstOfRoomNumbers))
              (setq lstOfRoomNumbers (SortListOfSublistsByItem lstOfRoomNumbers 2))
              (setq lstOfRoomNumbers (SortListOfSublistsByItem lstOfRoomNumbers 0))
              (setq lstOfRoomNumbers (SortListOfSublistsByItem lstOfRoomNumbers 1))
              (setq lstRoomNumbers   (mapcar '(lambda (X)(apply 'strcat X)) lstOfRoomNumbers))
     
         )
      (if blnLists
       (mapcar 'list lstRoomNumbers)
       lstRoomNumbers
      )
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to sort a list of sublists by Item
    ;___________________________________________________________________________________________________________|
    
    (defun SortListofSublistsbyItem (lstOfSublists intItem)
     (vl-sort lstOfSublists '(lambda (X Y) (< (nth intItem X) (nth intItem Y))))
    )
    
    
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to check the length of each sublist in a list of sublists
    ;___________________________________________________________________________________________________________|
    
    (defun SublistsEqualLength (lstOfSublists / intCharacters lstOfSublists2)
     (if (setq intCharacters (apply 'max (mapcar 'length lstOfSublists)))
      (foreach lstSublist lstOfSublists
       (while (< (length lstSublist) intCharacters)
        (setq lstSublist (reverse (cons "" (reverse lstSublist))))
       )
       (setq lstOfSublists2 (cons lstSublist lstOfSublists2))
      )
     )
     (reverse lstOfSublists2)
    )
    
    (princ "!")
    (vl-load-com)
    Attached Files Attached Files
    AutomateCAD

  4. #14
    Member
    Join Date
    2013-07
    Posts
    20
    Login to Give a bone
    0

    Default Re: Sorting a list of that contains a list of alphanumeric room numbers

    Thanks for your wonderful program, I will test it at work on some of our more complicated floor plans.
    Code:
    ;; When it is Level G 
    '(("G00MSA") ("G00ESA") ("G00ESB") ("G18E") ("G18C") ("G99") ("G00STD") ("G00STE") ("G12F") ("G12E") ("G12B") ("G12D") ("G12C") ("G12A") ("G11") ("G00VSE") ("G12") ("G00ZPG") ("G08") ("G09") ("G00VSD") ("G07") ("G05") ("G04") ("G14A") ("G14") ("G16") ("G17") ("G15EA") ("G03") ("G02") ("G00VSC") ("G21") ("G00CRA") ("G20") ("G18") ("G18EA") ("G18A") ("G18B") ("G18BA") ("G18BBA") ("G18BB") ("G00ZPF") ("G00ZPD") ("G00ZPE") ("G00ZPC") ("G00ZPB") ("G97") ("G19") ("G19A") ("G00ZPH") ("AG18") ("AG18A") ("AG18AA") ("AG18BA") ("AG18B") ("AG18AB"))
    
    ;; yeilds
    
    '(("G00CRA") ("G00ESA") ("G00ESB") ("G00MSA") ("G00STD") ("G00STE") ("G00VSC") ("G00VSD") ("G00VSE") ("G00ZPB") ("G00ZPC") ("G00ZPD") ("G00ZPE") ("G00ZPF") ("G00ZPG") ("G00ZPH") ("G02") ("G03") ("G04") ("G05") ("G07") ("G08") ("G09") ("G11") ("G12") ("G12A") ("G12B") ("G12C") ("G12D") ("G12E") ("G12F") ("G14") ("G14A") ("G15EA") ("G16") ("G17") ("AG18") ("AG18A") ("AG18AA") ("AG18AB") ("AG18B") ("AG18BA") ("G18") ("G18A") ("G18B") ("G18BA") ("G18BB") ("G18BBA") ("G18C") ("G18E") ("G18EA") ("G19") ("G19A") ("G20") ("G21") ("G97") ("G99"))
     
    ;; but when it is Level 1
    
    (("100MSA") ("100ESA") ("100ESB") ("118E") ("118C") ("199") ("100STD") ("100STE") ("112F") ("112E") ("112B") ("112D") ("112C") ("112A") ("111") ("100VSE") ("112") ("100ZP1") ("108") ("109") ("100VSD") ("107") ("105") ("104") ("114A") ("114") ("116") ("117") ("115EA") ("103") ("102") ("100VSC") ("121") ("100CRA") ("120") ("118") ("118EA") ("118A") ("118B") ("118BA") ("118BBA") ("118BB") ("100ZPF") ("100ZPD") ("100ZPE") ("100ZPC") ("100ZPB") ("197") ("119") ("119A") ("100ZPH") ("A118") ("A118A") ("A118AA") ("A118BA") ("A118B") ("A118AB"))
    
    
    ;; yeilds
    
    '(("100CRA") ("100ESA") ("100ESB") ("100MSA") ("100STD") ("100STE") ("100VSC") ("100VSD") ("100VSE") ("100ZP1") ("100ZPB") ("100ZPC") ("100ZPD") ("100ZPE") ("100ZPF") ("100ZPH") ("102") ("103") ("104") ("105") ("107") ("108") ("109") ("111") ("112") ("112A") ("112B") ("112C") ("112D") ("112E") ("112F") ("114") ("114A") ("115EA") ("116") ("117") ("118") ("118A") ("118B") ("118BA") ("118BB") ("118BBA") ("118C") ("118E") ("118EA") ("A118") ("A118A") ("A118AA") ("A118AB") ("A118B") ("A118BA") ("119") ("119A") ("120") ("121") ("197") ("199"))
    Note: see room variants 118 vs G118. When its G18, then AG18 is before G18. But when it is 118, Then A118 is after. Is it possible and / or easy to have them be the same order regardless of what floor they are on?
    Last edited by frisbee; 2017-11-27 at 02:07 PM.

  5. #15
    Member
    Join Date
    2013-07
    Posts
    20
    Login to Give a bone
    0

    Default Re: Sorting a list of that contains a list of alphanumeric room numbers

    peter, How difficult would it be for you to modify your program to allow an extra parameter that indicates which column has room number information? And incorporating the Nth function instead of 'car and returning the sub-lists sorted. And what happens when the sub-lists are dotted pairs? My solution to the dotted pairs was to convert them to paired lists, do the sort, then convert back to dotted pairs.
    Last edited by frisbee; 2017-11-27 at 03:58 PM.

  6. #16
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: Sorting a list of that contains a list of alphanumeric room numbers

    Before we discuss changing the code, let explain how it works.

    If the list is '(("G00ZPF") ("G00ZPG")) what it does is look at the numerals and parses the strings into '(("G" "00" "ZPF")("G" "00" "ZPG")) and based on the way you described the room numbers the number is dominant.

    So I first sort the list of sublists by the nth 2 and then nth 0 and last nth 1.

    Then I recombine the strings and turn them back into lists.

    As far as the dotted pairs, I choose not not use them, just because they are trickier than lists.

    Anyways, I think you can figure out what I did and make the necessary tweeks.

    P=
    AutomateCAD

  7. #17
    Member
    Join Date
    2013-07
    Posts
    20
    Login to Give a bone
    0

    Default Re: Sorting a list of that contains a list of alphanumeric room numbers

    Thanks for taking the time to explain. To be honest, no I am not able to tweak your coding. It is not very important to correct the behavior for floors that begin with letters. But if possible, it would be greatly appreciated if you can at least change your coding to utilize the nth function instead and return the originally provided list sorted, this would be and exceptional improvement and will be greatly appreciated

    Here the room number is in the fourth column
    '(("D" "3" "111" "104A" "junk5")
    ("A" "5" "xxx" "A104A" "junk3")
    )

    Here the room number is in the second column
    '((<Entity name: 3a346500> "100CRF")
    (<Entity name: 3a3465a0> "100STB")
    )

    Thanks again for your amazing little program.
    Last edited by frisbee; 2017-11-30 at 04:56 PM.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. List Sorting in Lisp
    By avinash00002002 in forum AutoLISP
    Replies: 7
    Last Post: 2014-09-14, 05:59 PM
  2. Sorting parameters list
    By dduarte in forum Revit Architecture - General
    Replies: 3
    Last Post: 2009-02-10, 04:50 PM
  3. sorting drawing list
    By ray salmon in forum Revit Architecture - General
    Replies: 2
    Last Post: 2009-01-24, 12:09 AM
  4. Sorting a drawing list
    By WolffG in forum Revit Architecture - General
    Replies: 4
    Last Post: 2005-11-07, 07:54 PM
  5. Sorting a drawing list
    By christo4robin in forum Revit Architecture - General
    Replies: 1
    Last Post: 2004-01-14, 06:58 PM

Tags for this Thread

Posting Permissions

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