[LISP函数]保存变量至txt,从txt读取变量
;保存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
)
) {:soso_e179:} :Q:Q获得列表框指定的宏工程对象:Q :D多谢分享了!!!! 这个很好用。 很好用!谢谢分享 正需要,支持楼主大人了! 感谢分享。。。。。。。。。。。 点个赞,必须的 谢谢分享。 正需要,支持楼主大人了! 支持楼主{:1_1:}{:1_1:}{:1_1:}
页:
[1]