Code help for lists.

Discussion in 'AutoCAD' started by BillZ, Dec 7, 2004.

  1. BillZ

    BillZ Guest

    R2005 Vlisp:
    I need some help on how to code this part of my program.
    I am fairly new to Vlisp and have not learned all the polished techiques.

    I have a list of CNC plot files that I aquire with:

    Code:
    (setq PLTList (vl-directory-files "G:/SigmaNestLabels/" "*.PS" 1))
    
    4281_1.PS
    4281_2.PS
    4281_3.PS
    4281_4.PS
    4281_5.PS
    4281_6.PS
    4281_full.PS
    4281_nest_1.PS
    4281_nest_2.PS
    4281_nest_3.PS
    4282_1.PS
    4282_2.PS
    4282_3.PS
    4282_4.PS
    4282_5.PS
    4282_full.PS
    4282_nest_1.PS
    4282_nest_2.PS
    4282_nest_3.PS
    4285_1.PS
    4285_2.PS
    4285_3.PS
    4285_4.PS
    4285_5.PS
    4285_6.PS
    4285_7.PS
    4285_8.PS
    4285_9.PS
    4285_full.PS
    4285_nest_1.PS
    4285_nest_2.PS
    4285_nest_3.PS

    Note in this sample list that each program number has four nest plots.
    #_full.ps, and one each of nest_1.ps, nest_2.ps and nest_3.ps.
    This covers the nest program part of the plots.
    Then each nest program has a number of parts plots.
    #_1.ps, #_2.ps, ect. (as many numbers as needed to plot all the parts).

    Now comes the trickey part. I need to duplex the 4 program nest plot files (4 each),
    to the parts plot files (first 4 of any number of parts plots).
    I am not having trouble with the duplexing,I have that down pat.
    I have to get #_1.ps duplexed with #_full.ps, #_2.ps duplexed
    with #_nest_1.ps ect. until all 4 nest plots are duplexed.

    This is what I have done so far (shown below), it works and I am satisfied so far:

    1.) I get a sublist of each file name that begins with the same program # using:

    Code:
    (while PLTList
    (setq TMPList (vl-remove-if-not '(lambda (x)(= (substr x 1 4)(substr (car PLTList) 1 4))) PLTList) ;get same name list.
    PLTList (vl-remove-if '(lambda (x)(member x TMPList)) PLTList)                               ;remove from main list.
    )
    
    This give me for example:
    Command: !tmplist
    ("4281_1.PS" "4281_2.PS" "4281_3.PS" "4281_4.PS" "4281_5.PS" "4281_6.PS"
    "4281_full.PS" "4281_nest_1.PS" "4281_nest_2.PS" "4281_nest_3.PS")


    I hope I have explained this clearly so far.
    This next part is what I am not too happy with, although it works, I am looking for a more elegant way. :)

    2.) From TMPList (which is all matching nest numbers), I need to extract the filenames that get duplexed.


    Code:
    (setq FileNa (substr (car TMPList) 1 4)                                             ;program name incase I need to create a blank file for nest.
    FullNest (car (vl-remove-if-not '(lambda (x)(wcmatch x "*full*")) TMPList))   ;First Nest plot.
    TMPList (vl-remove-if '(lambda (x)(wcmatch x "*full*")) TMPList)              ;trim TMPlist of item.
    Nest_2 (car (vl-remove-if-not '(lambda (x)(wcmatch x "*nest_1*")) TMPList))   ;partial nest (3 part).
    TMPList (vl-remove-if '(lambda (x)(wcmatch x "*nest_1*")) TMPList)
    Nest_3 (car (vl-remove-if-not '(lambda (x)(wcmatch x "*nest_2*")) TMPList))
    TMPList (vl-remove-if '(lambda (x)(wcmatch x "*nest_2*")) TMPList)
    Nest_4 (car (vl-remove-if-not '(lambda (x)(wcmatch x "*nest_3*")) TMPList))
    TMPList (vl-remove-if '(lambda (x)(wcmatch x "*nest_3*")) TMPList)
    Plot_1 (car (vl-remove-if-not '(lambda (x)(= (substr x 6 1) "1")) TMPList))
    TMPList (vl-remove-if '(lambda (x)(= (substr x 6 1) "1")) TMPList)
    Plot_2 (car (vl-remove-if-not '(lambda (x)(= (substr x 6 1) "2")) TMPList))
    TMPList (vl-remove-if '(lambda (x)(= (substr x 6 1) "2")) TMPList)
    Plot_3 (car (vl-remove-if-not '(lambda (x)(= (substr x 6 1) "3")) TMPList))
    TMPList (vl-remove-if '(lambda (x)(= (substr x 6 1) "3")) TMPList)
    Plot_4 (car (vl-remove-if-not '(lambda (x)(= (substr x 6 1) "4")) TMPList))
    TMPList (vl-remove-if '(lambda (x)(= (substr x 6 1) "4")) TMPList)
    MoveList (cons TMPList MoveList)  ;any files left over that are not duplexed that get moved to server.
    )
    
    Keep in mind that the code has to be flexible enough so that if there is not a part #_3 or #_4 file, it does not crash (right now it just returns nil for that item).

    Just looking for some expertise on hadeling this part of my code.

    What I do after this, using these variable names, works okay too:

    Code:
    (if (and (findfile (strcat "G:/SigmaNestLabels/" FullNest))
    (findfile (strcat "G:/SigmaNestLabels/" Plot_1))
    )
    (progn (Duplex (strcat "G:\\SigmaNestLabels\\" Plot_1)(strcat "G:\\SigmaNestLabels\\" FullNest)) ;duplex
    
    (setq MoveList (apply 'append MoveList))                             ;move this file list to server.
    

    TIA

    Bill
     
    BillZ, Dec 7, 2004
    #1
  2. BillZ

    BillZ Guest

    Well,
    Unless someone else has found a better way:

    Code:
    (setq PLTList (vl-directory-files "G:/SigmaNestLabels/" "*.PS" 1))
    ;---;
    (while PLTList
    (setq TMPList (vl-remove-if-not '(lambda (x)(= (substr x 1 4)(substr (car PLTList) 1 4))) PLTList) ;get sub list.
    PLTList (vl-remove-if '(lambda (x)(member x TMPList)) PLTList)                               ;remove from main list.
    )
    ;---;
    (setq FileNa (substr (car TMPList) 1 4)
    NestList (vl-remove-if-not '(lambda (x)(wcmatch x "*nest_*")) TMPList)    ;list of 4 nest files.
    PartList (mapcar '(lambda (a)(vl-remove-if-not '(lambda (x)(wcmatch x (strcat "*" FileNa "_" (itoa a) "*"))) TMPList)) '(0 1 2 3))  ;wish I could get this as one list.
    PartList (apply 'append PartList)                                       ;so I wouldn't have to do this line.
    TMPList (vl-remove-if '(lambda (x)(member x NestList)) TMPList)
    MoveList (cons (vl-remove-if '(lambda (x)(member x PartList)) TMPList) MoveList)
    )
    ;---;
    (while (< (length PartList) 4)               ;in case there's not enough sheets.
    (setq PartList (append PartList (list "LackingPlotFile.PS")))
    )
    ;---;
    (while (< (length NestList) 4)
    (setq PartList (append NestList (list "miss_prg.PS")))
    )
    ;---;
    
    This way at least I can run the two lists with mapcar to duplex. Should be less code.

    Bill
     
    BillZ, Dec 7, 2004
    #2
  3. BillZ

    BillZ Guest

    I finalized the code here:
    Wcmatch was the answer for getting a single list of the 4 part plots.

    Code:
    ;---;
    (setq PLTList (vl-directory-files "G:/SigmaNestLabels/" "*.PS" 1)
    PLTList (vl-remove-if '(lambda (x)(member x (list "LackingPlotFile.PS" "miss_prg.PS"))) PLTList)
    )
    ;---;
    (while PLTList
    (setq TMPList (vl-remove-if-not '(lambda (x)(= (substr x 1 4)(substr (car PLTList) 1 4))) PLTList) ;get sub list.
    PLTList (vl-remove-if '(lambda (x)(member x TMPList)) PLTList)                               ;remove from main list.
    )
    ;---;
    (setq FileNa (substr (car TMPList) 1 4)
    NestList (vl-remove-if-not '(lambda (x)(wcmatch x "*nest_*")) TMPList)
    PartList (vl-remove-if-not '(lambda (x)(wcmatch x (strcat "*" FileNa "_[0-3]*"))) TMPList)
    MoveList (cons (vl-remove-if '(lambda (x)(member x (append NestList PartList))) TMPList) MoveList)
    )
    ;---;
    (while (< (length PartList) 4)
    (setq PartList (append PartList (list "LackingPlotFile.PS")))
    )
    ;---;
    (while (< (length NestList) 4)
    (setq NestList (append NestList (list "miss_prg.PS")))
    )
    ;---;
    
    The two lists returned look like this:

    !NestList
    ("4281_nest_0.PS" "4281_nest_1.PS" "4281_nest_2.PS" "4281_nest_3.PS")

    !PartList
    ("4281_0.PS" "4281_1.PS" "4281_2.PS" "4281_3.PS")

    Being I started this, I thought I should finish.
    I think it has come a long way from my first post.

    Thanks for being there. :)


    Bill
     
    BillZ, Dec 8, 2004
    #3
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.