AutoCAD:运行AutoLisp函数的脚本



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

该脚本应该运行一个 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...")
    )
)

脚本只需要运行此命令,关闭图形,而不保存。

所以我试过(测试.scr)

(ar_list)
quit
n

但这给了我错误:

命令:(ar_list)错误的参数类型:字符串 nil

我认为ar_list需要从defun c:areas那里得到一些东西,但我不知道是什么。在命令栏中输入区域后,ar_list工作。所以我也尝试了

地区(ar_list)退出n

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

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

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",则可能是问题,但是如果我没有错的话,还有其他错误消息。

相关内容

  • 没有找到相关文章

最新更新