0

我有一个可以在一堆图纸上运行脚本的工作批处理文件。

该脚本应该运行一个 lisp 函数,但该函数似乎只在主函数运行后运行。

由于我对 lisps 了解不多,因此我将尝试提供我所拥有的信息。

lsp:

(princ "\nLoading AREAS...")

(defun c:areas(); Start the program.
    (setvar "cmdecho" 0)
    (if (= (getvar "tilemode") 1)
        (progn
            (command "_.ucs" "_world")        
            (setq osnp (getvar "osmode"))
            (setq laag (getvar "clayer"))
            (setvar "osmode" 0)
            (setq dimz (getvar "dimzin"))
            (setvar "dimzin" 0)       
            (ge_dellay ladeptmp)
            (if (>= (substr (getvar "acadver") 1 2) "15")
                (ge_convert)
            )
            (setq allsel (list (cons 0 "POLYLINE")'(-4 . "<OR")(cons 8 ladeppoly)(cons 8 ladeptraf)'(-4 . "OR>")'(-3 ("COSBI"))))
            (setq depsel (list (cons 0 "POLYLINE")(cons 8 ladeppoly)'(-3 ("COSBI"))))
            (setq areasel (list (cons 0 "POLYLINE")(cons 8 ladeptraf)'(-3 ("COSBI"))))
            (setq textsel (list (cons 0 "TEXT")(cons 8 ladeptext)'(-3 ("COSBI"))))
            (setq dcl_area (load_dialog "areas"))
            (setq dcl_gen (load_dialog "general"))
            (setq intp nil dparea nil seltot nil)
            (ar_setdep)
            (ar_dia)
            (if (= what_next 1)(ar_setlay))
            (if (= what_next 2)(ar_check))
            (if (= what_next 3)(ar_startcheck))
            (unload_dialog dcl_area)
            (unload_dialog dcl_gen)
            (setvar "osmode" osnp)
            (setvar "clayer" laag)
            (setvar "dimzin" dimz)
            (ge_dellay ladeptmp)
        )
        (alert "Only allowed in original drawing...")
    )
    (princ)
)

紧随其后的是一些其他(不确定)不太重要的功能,例如 ar_dia - 它会打开一个对话框,其中包含调用其他功能的按钮。其他功能之一是 AR_LIST,这是我需要在脚本中对批处理文件打开的每个文件运行的功能。

ar_list 向下几个街区,看起来像这样

  (defun ar_list(); Make department/areas list.
    (setq sel (ssget "x" allsel))
    (if sel
        (progn
            (setq temp (findfile "template.sqm"))
            (if temp
                (progn
                    (command "_.zoom" "_all")
                    (setq rowlist nil deplist nil)
                    (setq bestand (open temp "r"))
                    (setq row (read-line bestand))
                    (while row
                        (setq row (read-line bestand))
                        (if row 
                            (progn
                                (setq rowlist (cons (strcase (strcat (spatie (substr row 23 14)) "_-")) rowlist))
                                (setq deplist (cons (strcase (spatie (substr row 23 14))) deplist)) 
                            )
                        )
                    )
                    (setq country (ge_dir 3 "Country"))
                    (ge_dwg)
                    (if (= (strlen dwgnaam) 9); 3to4storenr
                        (progn
                            (setq store (substr dwgnaam (- (strlen dwgnaam) 3))); 3to4storenr
                            (setq floor (substr dwgnaam (- (strlen dwgnaam) 5) 2)); 3to4storenr
                            (setq num 0)
                            (repeat (sslength sel)
                                (setq depname (cdr (cadadr (assoc -3 (entget (ssname sel num)'("COSBI"))))))
                                (if (not (wcmatch depname "*`island*"))
                                    (progn
                                        (setq ename (ssname sel num))
                                        (command "_.area" "_a" "_o" ename "")
                                        (ge_puntlist ename)
                                        (setq numpol 0)
                                        (setq selpol (ssget "_wp" puntlist allsel))
                                        (if selpol
                                            (repeat (sslength selpol)
                                                (setq islname (cdr (cadadr (assoc -3 (entget (ssname selpol numpol)'("COSBI"))))))
                                                (if (= islname (strcat depname "-island"))
                                                    (command "_s" "_o" (ssname selpol numpol) "")
                                                )
                                                (setq numpol (1+ numpol))
                                            )
                                        )
                                        (command "")
                                        (setq deparea (/ (getvar "area") 1000000))
                                        (if (not (member (strcase depname) deplist))
                                            (progn
                                                (setq deplist (cons (strcase depname) deplist))
                                                (setq rowlist (cons (strcase (strcat depname "_-")) rowlist))
                                            )
                                        )
                                        (setq nummem (- (length deplist)(length (member (strcase depname) deplist))))
                                        (setq deptot (nth nummem rowlist))
                                        (vindpos "_" deptot)
                                        (setq depareaold (substr deptot (+ pos 1)))
                                        (if (/= depareaold "-")
                                            (setq deparea (+ (atof depareaold) deparea))
                                        )
                                        (setq rowlist (subst (strcase (strcat depname "_" (rtos deparea 2 1))) (nth nummem rowlist) rowlist))
                                    )
                                )   
                                (setq num (1+ num))
                            )
                            (command "_.zoom" "_previous")
                            (setq rowlist (acad_strlsort rowlist)); 13-10-2014
                            (setq deplist (acad_strlsort deplist)); 13-10-2014
                            ;(setq rowlist (reverse rowlist))
                            ;(setq deplist (reverse deplist))
                            (ar_write)
                        )
                        (alert (strcat "Drawing name " dwgnaam " not correct, must be 9 characters.")); 3to4storenr
                    )
                )
                (alert "File TEMPLATE.SQM not found...")
            )
        )
        (alert "No department or traffic found...")
    )
)

脚本只需要运行这个命令,关闭绘图,不保存。

所以我尝试了(test.scr)

(ar_list)
quit
n

但这给了我错误:

命令:(ar_list) 错误参数类型:stringp nil

我认为 ar_list 需要来自 的东西defun c:areas,但我不知道是什么。ar_list 在命令栏中输入区域后起作用。所以我也试过

区域 (ar_list) 退出 n

,但是打开了区域对话框,并没有关闭它,阻塞了循环。此外,当我取消对话框时, ar_list 工作,但它再次打开区域对话框。我认为代码在脚本中重复出现。

任何帮助都会非常受欢迎。我在这里收到了相关帮助

4

1 回答 1

0

stringp nil 给我们一些建议,一些应该是文本字符串的变量实际上是 nil。可能是因为它从对话框控件中读取值(对话框不活动时不可用)。

很少有地方可能会导致这样的问题:

我们不知道发生了什么ge_dir ge_dwg ge_puntlist vindpos ar_write

ar_write也许想为对话写点东西?

变量dwgnaam用作字符串,但从未在此函数中初始化,(可能在其他地方?)

(setq depname (cdr (cadadr (assoc -3 (entget (ssname sel num)'("COSBI")))))) (if (not (wcmatch depname "*island*"))如果所选实体不包含 XData "cosbi",则可能有问题,但如果我没记错,还有其他错误消息。

于 2016-03-11T07:09:55.390 回答