@jens.tornblad wrote:
Wow! This is great! Real timesaver! A couple of questions regarding a couple of changes I thought of when I tried it out.
Is it possible to also purge the file? I tried adding
(command "_.-purge" "_A" "*" "_N")
after
(vla-startundomark adoc)
(command "_.-xref" "_D" "*")
(command "_.qsave")
(command "_.ucs" "_W")
without any luck. It purges the file but then the script appears to stop. I only want the "recent" file to get purged.
Also another change, if possible. I don't want the script to overwrite the old file if there's already one with the same date. In other words if an old file is already created for the day I don't want to overwrite that if the script is run again on that day.
Thank you very much for the help.
You're welcome, jens.tornblad!
The
(command "_.-purge" "_A" "*" "_N")
should not stop the code,
(defun c:demo (/ *error* adoc dwg dwg_old)
(setq adoc (vla-get-activedocument (vlax-get-acad-object)))
(defun *error* (msg)
(vla-endundomark adoc)
(cond
((not msg))
((member msg '("Function cancelled" "quit / exit abort")))
((princ (strcat "\n** Error: " msg " ** ")))
)
(if command-s
(command-s "_.undo" "")
(command "_.undo" "")
)
(princ)
)
(setq dwg (substr (getvar 'dwgname) 1 (- (strlen (getvar 'dwgname)) 4)))
(setq dwg_old (strcat "c:/Test/old/" dwg "_" (menucmd "M=$(edtime,$(getvar,date),YYMD)") ".dwg"))
(cond ((not (findfile dwg_old))
(vla-startundomark adoc)
(command "_.-xref" "_D" "*")
(command "_.qsave")
(command "_.ucs" "_W")
(command "_.-purge" "_A" "*" "_N")
(if (findfile (strcat "c:/Test/recent/" (getvar 'dwgname)))
(progn
(vl-file-copy
(strcat "c:/Test/recent/" (getvar 'dwgname))
(strcat "c:/Test/old/" dwg "_" (menucmd "M=$(edtime,$(getvar,date),YYMD)") ".dwg")
)
(vl-file-delete (strcat "c:/Test/recent/" (getvar 'dwgname)))
(vl-file-copy
(strcat (getvar 'dwgprefix) (getvar 'dwgname))
(strcat "c:/Test/recent/" (getvar 'dwgname))
)
)
(vl-file-copy
(strcat (getvar 'dwgprefix) (getvar 'dwgname))
(strcat "c:/Test/recent/" (getvar 'dwgname))
)
)
(*error* nil)
)
(T
(princ "\nA backup has already been created today... ")
)
)
(princ)
)
Untested, I don't have AutoCAD in this laptop...
Hope this helps,
Henrique
Henrique