文件另存lisp,求帮助能判断一下时间格式,只保留最新的时间,免得文件重命名越来...
文件另存lisp,求帮助能判断一下时间格式,只保留最新的时间,免得文件重命名越来越长,谢谢;;直接按时间更改名字另保并打开目录
(defun c:sav ( / date dwgtitled newname oldname path)
(if (= (getvar "DWGTITLED") 0)
(ALERT "请先保存文件!")
(progn
(setq path (getvar "DWGPREFIX")
oldname (vl-filename-base (getvar "DWGNAME"))
)
(setq date (menucmd "M=$(edtime,$(getvar,date),-)"))
(setq newname (strcat path oldname date))
(command "_.save" newname)
(princ (strcat "\n---本图已另存为" newname ".dwg"))
)
)
(initget "Q")
(setq key (getkword "\n本图已另存是否打开另存文件夹 [打开(Q)/ <不打开(默认)>"))
(if (= key "Q")
(startapp (strcat "explorer /select, " (getvar "dwgprefix") (getvar "dwgname") ", /e"))
)
(princ)
)
本帖最后由 ㄘ丶转裑ㄧ灬 于 2014-11-30 20:45 编辑
暂时没弄懂这样另存的意义是什么。。
建议去看下G版的自动备份图纸
http://bbs.mjtd.com/forum.php?mo ... 1521&fromuid=401847
或者G版的另一个备份图纸
http://bbs.mjtd.com/thread-101512-1-1.html ;;直接按时间更改名字另保并打开目录
(defun c:sav ( / date dwgtitled newname oldname path)
(if (= (getvar "DWGTITLED") 0)
(ALERT "请先保存文件!")
(progn
(setq path (getvar "DWGPREFIX")
oldname (vl-filename-base (getvar "DWGNAME")))
(setq date (menucmd "M=$$(edtime,$$(getvar,date),-)"))
(if (wcmatch oldname (strcat "*" (substr date 1 4) "*")) (progn
(setq n 1)
(while (/= (substr date 1 4) (substr oldname n 4)) (setq n (1+ n)))
(setq oldname (substr oldname 1 n))
))
(setq newname (strcat path oldname date))
(command "_.save" newname)
(princ (strcat "\n---本图已另存为" newname ".dwg"))
))
(initget "Q")
(setq key (getkword "\n本图已另存是否打开另存文件夹 [打开(Q)/ <不打开(默认)>"))
(if (= key "Q")
(startapp (strcat "explorer /select, " (getvar "dwgprefix") (getvar "dwgname") ", /e"))
)
(princ)
)
我打开了Drawing1-.dwg
使用命令: sav
"C:\tangent\TWT9\sys18x64\Drawing1-$ $(EDTIME,??) ":
无效文件名。
---本图已另存为C:\tangent\TWT9\sys18x64\Drawing1-$ $(EDTIME,??)
.dwg
麻烦z版帮忙修改一下,谢谢了 图纸另存为实际上就是复制一份,建议参考函数:vl-file-copy 本帖最后由 tranney 于 2014-11-30 22:33 编辑
哎呀呀,等了这么久,看到了一个处理字符串的帖子,然后自己处理了一下居然成功了,
另存的文件=文件名-[年-月-日][时-分-秒]
希望大家喜欢
;主函数
(defun c:sav ( / date dwgtitled newname oldname oldname1 path)
(if (= (getvar "DWGTITLED") 0)
(ALERT "请先保存文件!")
(progn
(setq path (getvar "DWGPREFIX")
oldname (vl-filename-base (getvar "DWGNAME"))
)
(setq oldname1 (HH:GetBeforeStr1 oldname "-"))
(setq date (menucmd "M=$(edtime,$(getvar,date),-)"))
(setq newname (strcat path oldname1 date))
(command "_.saveas" "" newname "")
(princ (strcat "\n---本图已另存为" newname ".dwg"))
)
)
)
;子函数1
(defun HH:GetBeforeStr1 (str st);区分大小写
(car (xd::string:regexps (strcat "[^" st "]+") str "I"))
)
;子函数2
(defun XD::String:RegExpS (pat str key / end keys matches x)
(if (not *xxvbsexp)
(setq *xxvbsexp (vlax-get-or-create-object "VBScript.RegExp"))
)
(vlax-put *xxvbsexp 'Pattern pat);;;;;;是'Pattern出错的,
(if (not key)
(setq key "")
)
(setq key (strcase key))
(setq keys '(("I" "IgnoreCase") ("G" "Global")
("M" "Multiline")
)
)
(mapcar
'(lambda (x)
(if (wcmatch key (strcat "*" (car x) "*"))
(vlax-put *xxvbsexp (read (cadr x)) 0)
(vlax-put *xxvbsexp (read (cadr x)) -1)
)
)
keys
)
(setq matches (vlax-invoke *xxvbsexp 'Execute str))
(vlax-for x matches (setq end (cons (vla-get-value x) end)))
(reverse end)
)
111111111111111
页:
[1]