- 积分
- 2218
- 明经币
- 个
- 注册时间
- 2022-9-23
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
66明经币
(vl-load-com)
(defun c:bbb (/ ;局部函数
*error* PEACE:SaveSysVarPeace
PEACE:ReadSysVarPeace SaveSysVar
SaveOsmode ;局部变量
dclname tempname filen
stream dcl_re ST
RT SS RS
)
;局部变量开始
;自定义错误函数
(defun *error* (msg)
(command ".UNDO" "E")
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **"))
)
(princ)
)
;保存peace系统变量,保存到cad安装目录下的PEACESYSVAL.TXT by PEACE 2013/05/25
(defun PEACE:SaveSysVarPeace (valname valvalue infotext
/ acadpath f
datalist data valvalue_old
i isthere
)
(setq acadpath (vlax-get-property (vlax-get-acad-object) 'Path))
(if (= infotext "")
(setq infotext "no infotext")
)
(if (null (findfile "PEACESYSVAL.TXT"))
(progn ;若文件不存在
(setq f (open (strcat acadpath "\\PEACESYSVAL.TXT") "w"))
(prin1 (list valname valvalue infotext) f)
(close f)
)
(progn ;若文件已存在
(setq datalist '())
(setq f (open (strcat acadpath "\\PEACESYSVAL.TXT") "r"))
(while (setq data (read-line f))
(setq datalist (cons data datalist))
)
(close f)
(setq datalist (reverse datalist))
(setq i 0
isthere 0
)
(repeat (length datalist)
(if (= valname (car (read (nth i datalist))))
(progn
(setq
datalist (subst (vl-prin1-to-string
(list valname valvalue infotext)
)
(nth i datalist)
datalist
)
)
(setq isthere 1)
)
)
(setq i (1+ i))
)
(if (= 1 isthere)
(progn
(setq f (open (strcat acadpath "\\PEACESYSVAL.TXT") "w"))
(prin1 (read (nth 0 datalist)) f)
(close f)
(setq i 1)
(setq f (open (strcat acadpath "\\PEACESYSVAL.TXT") "a"))
(repeat (- (length datalist) 1)
(write-line "" f)
(prin1 (read (nth i datalist)) f)
(setq i (1+ i))
)
(close f)
)
(progn
(setq f (open (strcat acadpath "\\PEACESYSVAL.TXT") "a"))
(write-line "" f)
(prin1 (list valname valvalue infotext) f)
(close f)
)
)
)
)
(princ)
)
;读取peace系统变量 by PEACE 2013/05/25
(defun PEACE:ReadSysVarPeace (/ acadpath data datalist i f)
(setq acadpath (vlax-get-property (vlax-get-acad-object) 'Path))
(if (findfile "PEACESYSVAL.TXT")
(progn
(setq datalist '())
(setq f (open (strcat acadpath "\\PEACESYSVAL.TXT") "r"))
(while (setq data (read-line f))
(setq datalist (cons data datalist))
)
(reverse datalist)
(close f)
(setq i 0)
(repeat (length datalist)
(set (read (car (read (nth i datalist))))
;注意字符和表之间的转换,字符串是不能作为变量名的
(cadr (read (nth i datalist)))
;car对字符串也是不起作用的
)
(setq i (1+ i))
)
)
nil
)
)
(defun SaveSysVar ()
(PEACE:SaveSysVarPeace
"PEACE:MO_O"
PEACE:MO_O
"PEACE-MyOsmode捕捉模式"
)
(PEACE:SaveSysVarPeace
"PEACE:MO_T"
PEACE:MO_T
"PEACE-MyOsmode状态文字"
)
)
(defun SaveOsmode ()
(setq PEACE:MO_O (getvar "osmode")
PEACE:MO_T (menucmd
"m=$(edtime,$(getvar,DATE),YYYY/M/D hh:mm:ss)"
)
ST (strcat "最近保存于:" PEACE:MO_T)
RT (strcat "成功还原至:" PEACE:MO_T)
)
)
;局部函数结束
;主函数开始
(princ "PEACE-MyOsmode 捕捉模式保存于还原")
(PEACE:ReadSysVarPeace)
(if (not PEACE:MO_T)
(setq ST "未曾保存!"
RT "未曾保存!"
)
(setq ST (strcat "最近保存于:" PEACE:MO_T)
RT (strcat "成功还原至:" PEACE:MO_T)
)
) ;状态显示
(if (not PEACE:MO_O)
(setq PEACE:MO_O 0)
) ;捕捉模式
(setq SS 0
RS 0
)
(setq dclname
(cond
((setq tempname (vl-filename-mktemp "PEACEDCL.dcl")
filen (open tempname "w")
)
(foreach stream
'("\n"
"dcl01:dialog {\n"
" label = \"捕捉模式保存与还原\"; \n"
" :row { \n"
" :text {label=\"未曾保存!\" ; key=\"ea01\" ; } \n"
" } \n"
" :row { \n"
" :button{label=\"保存\" ; key = \"ea02\" ; edit_width = 10 ; height = 1.2 ; } \n"
" :button{label=\"还原\" ; key = \"ea03\" ; edit_width = 10 ; height = 1.2 ; } \n"
" } \n"
" ok_cancel;"
" }"
)
(princ stream filen)
)
(close filen)
tempname
)
)
)
(setq dcl_re (load_dialog dclname))
(if (not (new_dialog "dcl01" dcl_re))
(exit)
)
(mode_tile "accept" 2)
(set_tile "ea01" ST)
(action_tile
"ea02"
"(SaveOsmode)(set_tile \"ea01\" ST)(SETQ SS 1)"
)
(action_tile
"ea03"
"(setvar \"osmode\" PEACE:MO_O)(set_tile \"ea01\" RT)(SETQ RS 1)"
)
(action_tile "accept" "(SaveSysVar)(done_dialog)")
(action_tile "cancel" "(done_dialog)")
(start_dialog)
(unload_dialog dcl_re)
(vl-file-delete dclname)
(if (= SS 1)
(princ (strcat "\n*** " ST "!"))
)
(if (= RS 1)
(princ (strcat "\n*** " RT "!"))
)
(if (and (= SS 0) (= RS 0))
(princ "\n*** 未做任何修改, 程序退出!")
)
(princ)
)
|
|