Thursday, November 19, 2009

AutoCAD Civil 3D Crash Protection Snapshots

AutoCAD Civil 3D 2010 is a wonderful program. We love it. And it corrupts drawings irretrievably sometimes. So when we are working with Feature Lines, Projection Gradings, and Surfaces, we want to save snapshots often in case we find ourselves with a drawing in a condition we hate and can't fix.

Here is a little AutoLISP function you can use to Purge, Audit, Qsave, and copy a snapshot to an Archive sub-directory everytime you pause for a breath, stretch, or sip of water.


(defun
c:qa (/ bp bn dn dnbase dnext dp)
(command
"._-purge" "_Blocks" "*" "n"
"._-purge" "_SHapes" "*" "n"
"._-purge" "_Zero"
"._-purge" "_Empty"
"._-purge" "_Regapps" "*" "n"
"._audit" "y"
"._qsave"
)
(setq
;;Drawing file name
dn (getvar "dwgname")
dnbase
(vl-filename-base dn)
dnext
(vl-filename-extension dn)
;;Drawing folder with trailing (back) slash
dp (getvar "dwgprefix")
;;Backup sub-folder name
bp (strcat dp "Archive\\")
;;Backup file name including date and time stamp as yyyymmdd-hhmmss
bn
(strcat
dnbase "-"
(itoa (fix (getvar "cdate"))) "-"
(substr (itoa (+ 1000000 (fix (* 1000000 (rem (getvar "cdate") 1))))) 2)
dnext
)
)
(vl-mkdir bp)
(if (vl-file-copy (strcat dp dn) (strcat bp bn))
(princ (strcat "\nSnapshot " bn " copied to " bp))
)
(princ)
)


Revised 2009-11-20: Added leading zero to save time.
Revised 2010-09-24: Wrapped Lisp code for visibility.

2 comments:

David Dixon said...

very nice. thanks!

Wes Ashworth said...

Thanks, Tom! This has saved my bacon several times, now!