DaveC 发表于 2022-7-5 13:22:09

Sublist Manipulation - Plot Lo

        I need some help in the following lisp, I changing the CAD Plot log adding extra info that I need like the project number and a Flag and sorting in a different way.
        the problem is that if a have many plot cad files the changes are correct, but if I have only ONE file printed no changes occur, I creating a new plot log file avery time I plot, 
         and I copy that information to another file.
         
        any help will be really appreciated, thank so much.
         
         
        (SETQ p_Number "9999999")
        (SETQ Xcopies "1")
        (setq Flag "----")
       
        ;; USING THE DOSLIB_9.02 BY R. McNeel
        (setq File2Read (dos_readdelimitedfile "C:/Temp/AutoCad-PlotInfo.log"))   ;; Xlines 0)
                (setq XRow (nth index File2Read))
               ;; ;  ("U:\\100000\\elec\\765471 E-001-00 Ver01.dwg" "42X30" "8/24/2018 9:14:37 AM" "USERNAME" "Oce_TDS750_12th.pc3" "Oce B+ 12x18 in (Landscape)" "1:1.00011" nil)

       
                (setq DrwgName (nth 0 XRow))
                (setq TabPrint(nth 1 XRow))
                (setq Plot_date (nth 2 XRow))
                (setq User_name (nth 3 XRow))
                (setq PlotterName (nth 4 XRow))
                (setq PaperSize (nth 5 XRow))
               (setq datestr (itoa (fix (getvar 'cdate))) ; string in YYYYMMDD format
                         XMonthstr (substr datestr 5 2) ; month number as string
                        XYearstr (substr datestr 1 4) ; year
                       PlotDataFolder "c:/temp/"
               )
               (setq FileOpen (open (setq filestr (strcat PlotDataFolder XYearstr "-" XMonthstr " " "PlotInfo.log"))  ;;

DaveC 发表于 2022-7-5 13:41:23

soory i forgot the error message...
        error: bad argument type: consp "U:\\100000\\mech\\1523003 DM-101.00-01 verx2.dwg"
         
         
        (while (> Xlines 0)
              (setq XRow (nth index File2Read))
              ;  ("U:\\100000\\mech\\1523003 DM-101.00-01 verx2.dwg" "42X30" "8/24/2018 9:14:37 AM" "CANAS" "Oce_TDS750_12th.pc3" "Oce B+ 12x18 in (Landscape)" "1:1.00011" nil)

                  (setq DrwgName (nth 0 XRow))  ;;;

rlx 发表于 2022-7-5 14:04:18

Hi Dave,
         
        If you are correct about the line where the error occurs then Xrow is not a list at that time.
        here are some links about the subject :
        https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/error-bad-argument-type-consp-nil/td-p/4340061
        http://www.lee-mac.com/errormessages.html
         
        bad argument type: consp
        A function requiring a list argument has been passed an argument of incorrect data type with the value noted
        in the error message. Can be generated by passing any of the c..r functions, foreach, member, nth, or
        vl-sort-i functions an invalid list argument.
         
        I don't have doslib so can't help you with the entire routine but you could try to put in the visual lisp editor a breakpoint a the beginning of the line
         
 (setq XRow (nth index File2Read))         or at the beginning of while and put a watch or inspect Xrow.
         
        Something like
(while (and (> Xlines 0) (vl-consp Xrow)) .... may prevent the error.
         
        When at the beginning you do (setq File2Read (dos_readdelimitedfile ...)) File2Read should be a list and (setq Xlines (length File2read)) should at least be 1 else dos_readdelimitedfile doesn't do what you hope. Only other thing I could think of is that output of this function probably returns (list (list) (list).... ) and if there is (can) only be one , its output is just a list and not a list of lists (hope that makes sense) in that case you could try to test the length of File2Read before you enter the while loop :
         
(if (not (and (vl-consp File2read) (car File2read) (vl-consp (car File2read))))  (setq File2read (list File2read)))         
        something like if it is a bag with a bag don't brag else put it in a bag...
         
        but all of this is without being able to test your code so hope you can use something from my little story...
         
        gr. Rlx
         

Jef! 发表于 2022-7-5 14:17:03

Hi there. Your problem is indeed with dos_readdelimitedfile. It does return a list of list for multiple line csv, but doesn't return a list containing one list if you have only 1 line in the csv.
        (dos_readdelimitedfile "D:\\_2lines.csv") > returns > (("bob" 1 2) ("roger" "z" 3)) length 2, one per line from the csv
        (dos_readdelimitedfile "D:\\_1.csv") > returns > ("bob" 1 2) length 3, 1 per entry in the single line in the csv
        Basically if you have 2 or more entries, you need to use (nth entry file2read). If you have 1 entry, you don'T use (nth 0 file2read), but rather file2read as is. 
        You cannot just count the item qty in the list, because both multiple and single entry csv will lead to a multi element list. You have to verify if the 1rst element is a list or not, and act accordingly.
        Change that line  (setq XRow (nth index File2Read)) with the following
(if (listp(car File2Read))    (setq XRow (nth index File2Read))    (setq XRow File2Read))        and you should be good.
        Cheers.

DaveC 发表于 2022-7-5 14:28:32

thank you so much Rlx and Jef!.
         
        very informative... got the solution, I knew it was something simple.
         
        DC 
页: [1]
查看完整版本: Sublist Manipulation - Plot Lo