乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 82|回复: 4

[编程交流] Sublist Manipulation - Plot Lo

[复制链接]

3

主题

11

帖子

8

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-5 13:22:09 | 显示全部楼层 |阅读模式
        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"))  ;;
回复

使用道具 举报

3

主题

11

帖子

8

银币

初来乍到

Rank: 1

铜币
15
发表于 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

21

主题

1505

帖子

1551

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
81
发表于 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
         
  1.  (setq XRow (nth index File2Read))
or at the beginning of while and put a watch or inspect Xrow.
         
        Something like
  1. (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 :
         
  1. (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
         
回复

使用道具 举报

28

主题

317

帖子

292

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
140
发表于 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
  1. (if (listp(car File2Read))    (setq XRow (nth index File2Read))    (setq XRow File2Read))
and you should be good.
        Cheers.
回复

使用道具 举报

3

主题

11

帖子

8

银币

初来乍到

Rank: 1

铜币
15
发表于 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 
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-15 00:51 , Processed in 3.126620 second(s), 62 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表