系统变量的设置和重置-AutoCAD LISP

系统变量的设置和重置-AutoCAD LISP,lisp,autocad,autocad-plugin,autolisp,Lisp,Autocad,Autocad Plugin,Autolisp,我正在努力使在AutoCAD中绘制接线图非常容易,除了预先编程的按钮外,几乎没有其他按钮按下 其中一个涉及到LISP,它不能很好地设置系统变量,然后将它们重置为以前的状态。程序似乎执行了预期的功能,但没有达到预期的结果 一旦我的PLINE命令启动,变量就会重置。我需要PLINE启动、完成,然后重置变量 我尝试过在LISP中的命令中设置OrthoMode和SnapMode,以及通过(setvar(getvar…)命令 (defun varget() (setq lis'(“正交模式”“捕捉模式”)

我正在努力使在AutoCAD中绘制接线图非常容易,除了预先编程的按钮外,几乎没有其他按钮按下

其中一个涉及到LISP,它不能很好地设置系统变量,然后将它们重置为以前的状态。程序似乎执行了预期的功能,但没有达到预期的结果

一旦我的
PLINE
命令启动,变量就会重置。我需要
PLINE
启动、完成,然后重置变量

我尝试过在LISP中的命令中设置OrthoMode和SnapMode,以及通过
(setvar(getvar…)
命令

(defun varget()
(setq lis'(“正交模式”“捕捉模式”))
(setq变量(mapcar'getvar lis))
(setq变量1’(1))
(环境运输及工务局局长第0号)
(重复(长度lis)
(setvar(第n个lis)(第n个var1))
(setq编号(1+编号))
)
(普林斯)
)
(defun varset()
(环境运输及工务局局长第0号)
(重复(长度lis)
(setvar(第n个无lis)(第n个无var))
(setq编号(1+编号))
)
(普林斯)
)
(普林斯)
(定义C:导线()
(项目
(瓦吉特)
(setq前置层(getvar“clayer”))
(setq P(getstring“音频(A)/视频(V)/通信(CO)/同轴电缆(R)/控制(C)/(N)网络/(P)电源:))
(如果(=P“V”)(命令“-LAYER”“M”“VIDEO”“C”“150”“PLINE”暂停))
(如果(=P“A”)(命令“-LAYER”“M”“AUDIO”“C”“94”“PLINE”暂停))
(如果(=P“CO”)(命令“-LAYER”“M”“COMM”“C”“206”“PLINE”暂停)
(如果(=P“R”)(命令“-LAYER”“M”“COAX”“C”“44”“PLINE”暂停)
(如果(=P“C”)(命令“-LAYER”“M”“CONTROL”“C”“10”“PLINE”暂停))
(如果(=P“N”)(命令“-LAYER”“M”“NETWORK”“C”“210”“PLINE”暂停))
(如果(=P“P”)(命令“-LAYER”“M”“POWER”“C”“7”“PLINE”暂停))
(setvar“clayer”层)
(瓦塞特)
(普林斯)
);程序
);德芬
没有错误消息


我希望在执行
PLINE
命令后重置变量。

代码的问题在于,在尝试重置系统变量和完成程序评估之前,您仅暂停一个用户输入

相反,在继续进行程序评估之前,您需要使用一个循环来持续暂停用户输入

例如:

;; Define function, declare local symbols
(defun c:wire ( / col lay opt val var )

    ;; System variables to be modified within the program
    (setq var '(clayer orthomode snapmode cmdecho)
    ;; Retrieve current sys var values
          val  (mapcar 'getvar var)                
    ) ;; end setq

    ;; Predefine the getkword options
    (initget "Audio Video COmm R Control Network Power")
    ;; Prompt the user for input, default to "Audio" on null input
    (setq opt (cond ((getkword "\n[Audio/Video/COmm/Coax(R)/Control/Network/Power] <Audio>: ")) ("Audio")))

    ;; Define the layer & colour based on the option returned
    (cond
        (   (= opt "Audio")   (setq lay "AUDIO"    col  94))
        (   (= opt "Video")   (setq lay "VIDEO"    col 150))
        (   (= opt "COmm")    (setq lay "COMM"     col 206))
        (   (= opt "R")       (setq lay "COAX"     col  44))
        (   (= opt "Control") (setq lay "CONTROL"  col  10))
        (   (= opt "Network") (setq lay "NETWORK"  col 210))
        (   (= opt "Power")   (setq lay "POWER"    col   7))
    ) ;; end cond

    ;; Suppress command-line output for the -LAYER command
    (setvar 'cmdecho 0)
    ;; Create & set the layer & layer colour
    (command "_.-layer" "_M" lay "_C" col "" "")

    ;; Set everything except the first sys var
    (mapcar 'setvar (cdr var) '(1 1 1))
    ;; Initiate the PLINE command
    (command "_.pline")
    ;; Continuously pause for user input
    (while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\"))

    ;; Reset system variables
    (mapcar 'setvar var val)

    ;; Suppress the value returned by the last evaluated expression
    (princ) 
) ;; end defun

太棒了,非常感谢!在进一步研究代码时,我在IF语句之后添加了(while(>(>(“cmdactive”)0)pause,并且成功了。谢谢你的指点。我肯定会在我未来的计划中实施它们。
;; Define function, declare local symbols
(defun c:wire ( / *error* col lay opt val var )

    ;; Define local error handler
    (defun *error* ( msg )
        ;; Reset system variables
        (mapcar 'setvar var val)
        ;; Suppress the output of standard cancellation messages
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            ;; Print critical errors
            (princ (strcat "\nError: " msg))
        ) ;; end if
        (princ) ;; Suppress the value returned by the last evaluated expression
    ) ;; end defun

    ;; System variables to be modified within the program
    (setq var '(clayer orthomode snapmode cmdecho)
    ;; Retrieve current sys var values
          val  (mapcar 'getvar var)                
    ) ;; end setq

    ;; Predefine the getkword options
    (initget "Audio Video COmm R Control Network Power")
    ;; Prompt the user for input, default to "Audio" on null input
    (setq opt (cond ((getkword "\n[Audio/Video/COmm/Coax(R)/Control/Network/Power] <Audio>: ")) ("Audio")))

    ;; Define the layer & colour based on the option returned
    (cond
        (   (= opt "Audio")   (setq lay "AUDIO"    col  94))
        (   (= opt "Video")   (setq lay "VIDEO"    col 150))
        (   (= opt "COmm")    (setq lay "COMM"     col 206))
        (   (= opt "R")       (setq lay "COAX"     col  44))
        (   (= opt "Control") (setq lay "CONTROL"  col  10))
        (   (= opt "Network") (setq lay "NETWORK"  col 210))
        (   (= opt "Power")   (setq lay "POWER"    col   7))
    ) ;; end cond

    ;; Suppress command-line output for the -LAYER command
    (setvar 'cmdecho 0)
    ;; Create & set the layer & layer colour
    (command "_.-layer" "_M" lay "_C" col "" "")

    ;; Set everything except the first sys var
    (mapcar 'setvar (cdr var) '(1 1 1))
    ;; Initiate the PLINE command
    (command "_.pline")
    ;; Continuously pause for user input
    (while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\"))

    ;; Reset system variables
    (mapcar 'setvar var val)

    ;; Suppress the value returned by the last evaluated expression
    (princ) 
) ;; end defun