Vl-member-if or something like that?

Discussion in 'AutoCAD' started by BillZ, Nov 11, 2004.

  1. BillZ

    BillZ Guest

    R2005.

    I was wondering if there's a way to break up a list so that all the items of the list that have the same first four characters are processed as a sub list.
    The list is already sorted so that all the items that have the same first four numbers are together.

    Sample list:

    8293 58536 03 01 M361290 11/17/04 1800PS
    8293 60076 03 01 M361290 11/17/04 1800PS
    8293 60485 03 01 M361290 11/17/04 1800PS
    8293 60609 03 01 M361290 11/17/04 1800PS
    8293 60610 03 01 M361290 11/17/04 1800PS
    8293 60638 03 01 M361290 11/17/04 1800PS
    8293 60652 03 01 M361290 11/17/04 1800PS
    8293 66131 03 01 M361290 11/17/04 1800PS
    8279 30556 05 01 M361270 11/17/04 1700 PS
    8279 37041 05 01 M361270 11/17/04 1700 PS
    8279 37460 05 01 M361270 11/17/04 1700 PS
    8279 37461 05 01 M361270 11/17/04 1700 PS
    8279 51092 05 01 M361270 11/17/04 1700 PS
    8279 51094 05 01 M361270 11/17/04 1700 PS
    8279 53173 05 01 M361270 11/17/04 1700 PS
    8279 54775 05 01 M361270 11/17/04 1700 PS
    8279 54816 05 01 M361270 11/17/04 1700 PS
    8279 58514 05 01 M361270 11/17/04 1700 PS
    8279 58551 05 01 M361270 11/17/04 1700 PS
    8279 58593 05 01 M361270 11/17/04 1700 PS
    8279 58656 05 01 M361270 11/17/04 1700 PS
    8279 60076 05 01 M361270 11/17/04 1700 PS
    8240 77878 05 01 M361190 11/17/04 SCRAO
    8118 33110 03 01 M361100 11/17/04 1800SE,IFS
    8118 35706 03 01 M361100 11/17/04 1800SE,IFS
    8118 38975 03 01 M361100 11/17/04 1800SE,IFS
    8118 53175 03 01 M361100 11/17/04 1800SE,IFS
    8118 58753 03 01 M361100 11/17/04 1800SE,IFS

    I want :
    8293 58536 03 01 M361290 11/17/04 1800PS
    8293 60076 03 01 M361290 11/17/04 1800PS
    8293 60485 03 01 M361290 11/17/04 1800PS
    8293 60609 03 01 M361290 11/17/04 1800PS
    8293 60610 03 01 M361290 11/17/04 1800PS
    8293 60638 03 01 M361290 11/17/04 1800PS
    8293 60652 03 01 M361290 11/17/04 1800PS
    8293 66131 03 01 M361290 11/17/04 1800PS

    as a sub list to process during a loop.

    TIA

    Bill
     
    BillZ, Nov 11, 2004
    #1
  2. BillZ

    Kelie Feng Guest

    Something like this?
    Note: The list needs to be sorted list, as what is in your sample.

    ;;;(setq lst '("8293 58536 03 01 M361290 11/17/04 1800PS"
    ;;; "8293 60076 03 01 M361290 11/17/04 1800PS"
    ;;; "8293 60485 03 01 M361290 11/17/04 1800PS"
    ;;; "8293 66131 03 01 M361290 11/17/04 1800PS"
    ;;; "8279 30556 05 01 M361270 11/17/04 1700 PS"
    ;;; "8279 37041 05 01 M361270 11/17/04 1700 PS"
    ;;; "8279 54775 05 01 M361270 11/17/04 1700 PS"
    ;;; "8279 54816 05 01 M361270 11/17/04 1700 PS"
    ;;; "8240 77878 05 01 M361190 11/17/04 SCRAO"
    ;;; "8118 33110 03 01 M361100 11/17/04 1800SE,IFS"
    ;;; "8118 35706 03 01 M361100 11/17/04 1800SE,IFS"
    ;;; "8118 38975 03 01 M361100 11/17/04 1800SE,IFS"
    ;;; "8118 53175 03 01 M361100 11/17/04 1800SE,IFS"
    ;;; )
    ;;;)
    ;;;(setq newLst (KF:Break_SortedList lst)) returns
    ;;;
    ;;;'(("8293 58536 03 01 M361290 11/17/04 1800PS"
    ;;; "8293 60076 03 01 M361290 11/17/04 1800PS"
    ;;; "8293 60485 03 01 M361290 11/17/04 1800PS"
    ;;; "8293 66131 03 01 M361290 11/17/04 1800PS"
    ;;; )
    ;;; ("8279 30556 05 01 M361270 11/17/04 1700 PS"
    ;;; "8279 37041 05 01 M361270 11/17/04 1700 PS"
    ;;; "8279 54775 05 01 M361270 11/17/04 1700 PS"
    ;;; "8279 54816 05 01 M361270 11/17/04 1700 PS"
    ;;; )
    ;;; ("8240 77878 05 01 M361190 11/17/04 SCRAO")
    ;;; ("8118 33110 03 01 M361100 11/17/04 1800SE,IFS"
    ;;; "8118 35706 03 01 M361100 11/17/04 1800SE,IFS"
    ;;; "8118 38975 03 01 M361100 11/17/04 1800SE,IFS"
    ;;; "8118 53175 03 01 M361100 11/17/04 1800SE,IFS"
    ;;; )
    ;;;)

    (defun KF:Break_SortedList (lst / prevItem newLst i thisItem lastItem)
    (setq prevItem (car lst)
    newLst (list (list prevItem))
    i 1
    )
    (repeat (1- (length lst))
    (setq thisItem (nth i lst))
    (if (equal (substr thisItem 1 4) (substr prevItem 1 4))
    (setq lastItem (last newLst)
    newLst (subst (append lastItem (list thisItem)) lastItem newLst)
    )
    (setq newLst (append newLst (list (list thisItem))))
    )
    (setq prevItem thisItem
    i (1+ i)
    )
    )
    newLst
    )
     
    Kelie Feng, Nov 11, 2004
    #2
  3. BillZ

    BillZ Guest

    That works.

    I was thinking there would be a VL and lambda thingy out there, but maybe not.

    Thanks

    Bill
     
    BillZ, Nov 11, 2004
    #3
  4. BillZ

    James Allen Guest

    Hi Bill, I think massoc will help (at least in part) with this. I don't
    have it, but I've seen it posted here a few times.
    --
    James Allen, EIT
    Malicoat-Winslow Engineers, P.C.
    Columbia, MO


    of the list that have the same first four characters are processed as a sub
    list.
    ..... (snip) ....
     
    James Allen, Nov 11, 2004
    #4
  5. BillZ

    BillZ Guest

    I do believe you're right about that.

    I have it right here to try it out.

    Thanks


    Bill
     
    BillZ, Nov 11, 2004
    #5
  6. BillZ

    BillZ Guest

    That works for the first sub list.

    Code:
    (defun breaklist (key alist)
    (apply 'append
    (mapcar '(lambda (x)
    (if (eq (substr x 1 4) key)
    (list x)
    )
    )
    alist
    )
    )
    )
    
    Now I have to figure out how to remove the sublist from the test list for the next loop.

    First sublist:
    Code:
    ("8895 26960 05 01 M361930 11/17/04 1700 FISH" "8895 28719 05 01 M361930
    11/17/04 1700 FISH" "8895 34228 05 01 M361930 11/17/04 1700 FISH" "8895 37502
    05 01 M361930 11/17/04 1700 FISH" "8895 38903 05 01 M361930 11/17/04 1700 FISH"
    "8895 38906 05 01 M361930 11/17/04 1700 FISH" "8895 38925 05 01 M361930
    11/17/04 1700 FISH" "8895 38926 05 01 M361930 11/17/04 1700 FISH" "8895 39993
    05 01 M361930 11/17/04 1700 FISH" "8895 54931 05 01 M361930 11/17/04 1700 FISH"
    "8895 58484 05 01 M361930 11/17/04 1700 FISH" "8895 58565 05 01 M361930
    11/17/04 1700 FISH" "8895 58566 05 01 M361930 11/17/04 1700 FISH" "8895 58567
    05 01 M361930 11/17/04 1700 FISH" "8895 58568 05 01 M361930 11/17/04 1700 FISH"
    "8895 58606 05 01 M361930 11/17/04 1700 FISH" "8895 58607 05 01 M361930
    11/17/04 1700 FISH" "8895 58685 05 01 M361930 11/17/04 1700 FISH" "8895 58693
    05 01 M361930 11/17/04 1700 FISH" "8895 58695 05 01 M361930 11/17/04 1700 FISH"
    "8895 58697 05 01 M361930 11/17/04 1700 FISH" "8895 58709 05 01 M361930
    11/17/04 1700 FISH" "8895 77451 05 01 M361930 11/17/04 1700 FISH")
    
    Any ideas?

    Bill
     
    BillZ, Nov 11, 2004
    #6
  7. BillZ

    BillZ Guest

    I think I got it now.

    (while (setq lt (breaklist (nth cnt xx) x))(do whatever here)(setq cnt (+ (length lt) cnt)))

    Thanks to all that helped.

    Bill
     
    BillZ, Nov 11, 2004
    #7
  8. BillZ

    James Allen Guest

    Glad you got it to work for you. :)

    James
     
    James Allen, Nov 15, 2004
    #8
  9. BillZ

    BillZ Guest

    Here's the final version that seems to work the best, using one list.

    (setq cnt 0
    )
    (while (< cnt (length lt1)) ;(main loop.)
    (setq key (substr (nth cnt lt1) 1 4)
    tmplst (breaklist key lt1))

    ;;;do whatever to each sub list here.

    ) ;end while

    Bill
     
    BillZ, Nov 15, 2004
    #9
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.