本帖最后由 kucha007 于 2022-11-13 12:54 编辑
Lee Mac写的,简洁明了!整理了一下分享出来。
https://www.cadtutor.net/forum/topic/61171-codes-system-variables/?do=findComment&comment=505290
- (defun C:TT (/ *error* New_vars Old_vars)
- (defun *error* (msg)
- (foreach xx Old_vars (if xx (apply 'setvar xx)))
- (princ)
- )
- ;---------------------
- (setq New_vars '(
- (cmdecho 0);取消回显
- (OSMode 0);禁用捕捉
- (PICKSTYLE 0);取消编组
- (expert 5);禁止提示冲突(默认Yes)
- )
- )
- (setq Old_vars (mapcar
- '(lambda (a / b)
- (if (setq b (getvar (car a)))
- (progn
- (apply 'setvar a)
- (list (car a) b)
- )
- )
- )
- New_vars
- )
- )
- ;---------------------
- (progn
- ;;做某些事
- )
- ;---------------------
- (foreach xx Old_vars (if xx (apply 'setvar xx)))
- (princ)
- )
感觉也可以这样用:- (defun K:SysVar ()
- (if (not *Old_vars*)
- (progn
- (setq *New_vars* '(
- (cmdecho 0);取消回显
- (OSMode 0);禁用捕捉
- (PICKSTYLE 0);取消编组
- (expert 5);禁止提示冲突(默认Yes)
- )
- )
- (setq *Old_vars* (mapcar
- '(lambda (a / b)
- (if (and
- (setq b (getvar (car a)))
- (/= b (cadr a))
- )
- (progn
- (apply 'setvar a)
- (list (car a) b)
- )
- )
- )
- *New_vars*
- )
- )
- (setq *New_vars* nil)
- )
- (progn
- (foreach xx *Old_vars* (if xx (apply 'setvar xx)))
- (setq *Old_vars* nil)
- )
- )
- (princ)
- )
- (defun C:TT ()
- (defun *error* (msg)
- (K:SysVar);恢复系统变量
- (princ)
- )
- (K:SysVar);记录并修改系统变量
- ;你的程序
- (K:SysVar);恢复系统变量
- (princ)
- )
|