ankoron Posted September 9, 2016 Share Posted September 9, 2016 (edited) Hello, I'm using a very useful lisp code I found (very slightly modified), that saves the dwg file with a date and time stamp. Can someone help me so that the date and time appears before the file's name? For example I'd like the file to read "test 09-09-16_12.22'28.dwg''" instead of "09-09-16_12.22'28'' test.dwg" And more importantly, can each file be saved in a subfolder automatically created, that has the same name as the file? So if the file is named "test.dwg", a subfolder will be created and named "test" as well, automatically without any input from the user, containing all the saved files. Thank you in advance. This is the code I'm using: ;; TED KRUSH 9/23/02 ;;; Routine that was created @ Southern Maine Technical College. ;;; Saves Drawing an eariler version and then resaves as ;;; orginal version to maitain defualt save. ;; UPDATED 02/02/03 Added Date Sub-Routine ;; UPDATED 03/11/05 Revise version save 2002/R14 to 2004/2000 per upgrade to Autocad 2005 version ;; UPDATED 04/05/06 Adde StrPath Sub-Rountine, so as new file can be saved to folder. ;;;; *** Now We go to to Commerical Break for the Typical Legal Mumbo Jumbo *** ;;;; Permission to use, copy, modify, and distribute this software ;;;; for any purpose and without fee is hereby granted. ;;;; ;;;; I PROVIDE THIS PROGRAM "AS IS" AND WITH ALL FAULTS. I SPECIFICALLY DISCLAIM ANY ;;;; IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. I DO NOT ;;;; WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE UNINTERRUPTED OR ERROR FREE. (defun c:scon () ;;Error Trap utilizing the TedError Function (command ".undo" "m") (setq old_error *error*) (setq *error* tederror) ;;Start of Date defun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (defun TODAY (/ d yr mo day hr m s) ;define the function and declare all variabled local (setq d (rtos (getvar "CDATE") 2 6) ;get the date and time and convert to text yr (substr d 3 2) ;extract the year mo (substr d 5 2) ;extract the month day (substr d 7 2) ;extract the day hr (substr d 10 2) ;extract the hour m (substr d 12 2) ;extract the minute s (substr d 14 2) ;extract the second ) (setq dates (strcat mo "-" day "-" yr "_" hr "." m "'" s"'' ")) ;string 'em together (princ) ) ;;End of Date defun ;;Start of StrPath defun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (defun StrPath () (setq OldName (getvar "dwgname")) ;; Extracts the Drawing File Name (setq OldPath (getvar "dwgprefix")) ;; Extracts the Drawing Location (setq NewPath (vl-string-subst "\\Transfer-Outgoing\\" "\\Drawings\\" OldPath ) ) (setq OldFile (strcat OldPath OldName)) ; Text String for Old File (setq NewFile (strcat NewPath dates Oldname)) ; Text String for New File (princ) ) ;;End of StrPath defun ;; Main Rountine (today) (StrPath) (vl-mkdir NewPath) (setvar "expert" 4) (command "saveas" "2004" NewFile) ;New file with date Prefix (command "saveas" "2004" OldFile) ;Saves back to the Orginal File. (setvar "expert" 0) (setq *error* old_error) (princ) ) Edited September 9, 2016 by ankoron Quote Link to comment Share on other sites More sharing options...
SLW210 Posted September 9, 2016 Share Posted September 9, 2016 Please read the Code Posting Guidelines and edit your post to include the Code in Code Tags. [NOPARSE] Your Code Here [/NOPARSE] = Your Code Here Quote Link to comment Share on other sites More sharing options...
ankoron Posted September 9, 2016 Author Share Posted September 9, 2016 I'm getting there, I found through trial and error the code to create an empty subfolder with the same name as the dwg file. If someone could incorporate it into the rest of the code, I would be grateful, cause I'm a total noob with this. (vl-mkdir (vl-filename-base (getvar "dwgname"))) Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted September 9, 2016 Share Posted September 9, 2016 (defun c:scon ( / path oldExpert time) (if (zerop (getvar 'dwgtitled)) (princ "\nError: save drawing first ") (progn (setq oldExpert (getvar 'expert)) (setvar 'expert 4) (command "_.saveas" "_2004" "") ; Save original file. (setvar 'expert oldExpert) (setq time (vl-file-systime (strcat (getvar 'dwgprefix) (getvar 'dwgname)))) (setq path (strcat (vl-string-subst "\\Transfer-Outgoing\\" "\\Drawings\\" (getvar 'dwgprefix)) (vl-filename-base (getvar 'dwgname)) "\\" ) ) (vl-mkdir path) (setq path ; Add drawing name to path. (strcat path ; Ending in "\\". (vl-filename-base (getvar 'dwgname)) " " (strcat (if (> 10 (nth 1 time)) "0" "") (itoa (nth 1 time))) ; Month. "-" (strcat (if (> 10 (nth 3 time)) "0" "") (itoa (nth 3 time))) ; Day of the month. "-" (substr (itoa (nth 0 time)) 3) ; Year. "_" (strcat (if (> 10 (nth 4 time)) "0" "") (itoa (nth 4 time))) ; Hour. "." (strcat (if (> 10 (nth 5 time)) "0" "") (itoa (nth 5 time))) ; Minute. "'" (strcat (if (> 10 (nth 6 time)) "0" "") (itoa (nth 6 time))) ; Second. "''" ".dwg" ) ) (vl-file-delete path) ; Just in case... (vl-file-copy (strcat (getvar 'dwgprefix) (getvar 'dwgname)) path) ) ) ) Quote Link to comment Share on other sites More sharing options...
ankoron Posted September 10, 2016 Author Share Posted September 10, 2016 Roy, I really appreciate your help! I tried your code, but it doesn't save anything into the folder created and also returns the error: "Command: ; error: bad argument type: consp nil". Any ideas? Still, thank you for your effort and time. Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted September 10, 2016 Share Posted September 10, 2016 Apparently in AutoCAD there is a problem with (vl-file-systime). BricsCAD does not have this issue. Try this instead: (defun c:scon ( / path oldExpert time) (if (zerop (getvar 'dwgtitled)) (princ "\nError: save drawing first ") (progn (setq oldExpert (getvar 'expert)) (setvar 'expert 4) (command "_.saveas" "_2004" "") ; Save original file. (setvar 'expert oldExpert) (setq time (getvar 'tdupdate)) (setq path (strcat (vl-string-subst "\\Transfer-Outgoing\\" "\\Drawings\\" (getvar 'dwgprefix)) (vl-filename-base (getvar 'dwgname)) "\\" ) ) (vl-mkdir path) (setq path ; Add drawing name to path. (strcat path ; Ending in "\\". (vl-filename-base (getvar 'dwgname)) (menucmd (strcat "m=$(EDTIME," (rtos time 2 ", mo-dd-yy_hh.mm'ss'')")) ".dwg" ) ) (vl-file-delete path) ; Just in case... (vl-file-copy (strcat (getvar 'dwgprefix) (getvar 'dwgname)) path) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
ankoron Posted September 10, 2016 Author Share Posted September 10, 2016 Roy, it works perfectly! I can't thank you enough, I never would have done it by myself! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.