Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've been using a customized version of Lonnie's archive_and_save.lsp to archive my current DWG files. My version includes a few key modifications to better suit my workflow:
- Creates an "Archive" folder with a subfolder named after the current drawing.
- Copies only the current drawing into this folder, appending a timestamp to the filename.
- Verifies that the archive was successfully created before proceeding.
However, I’ve run into an issue with unsaved drawings. If the drawing hasn’t been saved yet, I’d like the lsp to display a dialog box notifying the user and then exit without executing the rest of the code.
I used AI to assist with some of the edits, so if anything looks off or could be improved, let me know.
(defun C:ACOPY (/ dwgDir dwgName currentDate year month day hour min sec formattedDateTime archiveDir subFolder fullPath srcFile dstFile newName ext)
;; Get the directory and filename of the current drawing
(setq dwgDir (getvar "dwgprefix"))
(setq dwgName (vl-filename-base (getvar "dwgname")))
(setq ext (vl-filename-extension (getvar "dwgname")))
;; Get and format the current date and time
(setq currentDate (rtos (getvar "cdate") 2 8)) ;; yyyymmdd.hhmmss
(setq year (substr currentDate 1 4))
(setq month (substr currentDate 5 2))
(setq day (substr currentDate 7 2))
(setq hour (substr currentDate 10 2))
(setq min (substr currentDate 12 2))
(setq sec (substr currentDate 14 2))
(setq formattedDateTime (strcat year "-" month "-" day "_" hour "-" min "-" sec))
;; Define archive folder and subfolder named after DWG file
(setq archiveDir (strcat dwgDir "archive\\"))
(setq subFolder (strcat archiveDir dwgName "\\"))
(vl-mkdir archiveDir)
(vl-mkdir subFolder)
;; Construct full path of the current DWG file
(setq srcFile (strcat dwgDir dwgName ext))
;; Construct destination file name with timestamp
(setq newName (strcat dwgName "_" formattedDateTime ext))
(setq dstFile (strcat subFolder newName))
;; Copy the current drawing file
(vl-file-copy srcFile dstFile)
;; Check if the file was actually created and display appropriate message
(if (findfile dstFile)
(alert (strcat "Current DWG file archived successfully to:\n\n" dstFile))
(alert "ERROR: Archive unsuccessful. File was not created.")
)
(princ)
)
Thanks in advance!
Solved! Go to Solution.