tive29 Posted April 28, 2017 Posted April 28, 2017 Have been using the below code with a marco button to open up the window explorer folder of the drawing location. ^C^C(startapp "Explorer" (strcat "/N,/E," (getvar "DWGPREFIX"))) I will search through a few 100 files from that folder location, make a copy of that file then place in another folder as a backup. Doing this multiple times Is there a lisp that can, without opening the folder location, directly make a copy of the current file (I do not mean saving current drawing) & place it into a predetermine folder? Quote
BrianTFC Posted April 28, 2017 Posted April 28, 2017 tive29 give this a try. (defun c:mysave ( / dwg pth tmp ) (setq pth "E:\Drawings" ;; Second save location dwg (strcat (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth)) "\\" (getvar 'dwgname)) ) (cond ( (zerop (getvar 'dwgtitled)) (princ "\nCurrent drawing is unsaved.") ) ( (and (setq tmp (findfile dwg)) (progn (initget "Yes No") (= "No" (getkword "\nFile already exists in second location, overwrite? [Yes/No] <Yes>: ")) ) ) ) ( t (command "_.qsave") (if tmp (vl-file-delete tmp)) (vl-file-copy (strcat (getvar 'dwgprefix) (getvar 'dwgname)) dwg) ) ) (princ) ) Quote
tive29 Posted April 28, 2017 Author Posted April 28, 2017 (edited) Hello BrianTFC. It save a copy to the predetermine folder, however that is not the intention cause the date of the file is now changed & is now base on when the lisp is run which is today 28/4/17. I only wanted to make a copy of the original drawing that is open, to another folder base on its original last saved date eg, 20/4/17, just like copying that file in windows explorer & placing it to another folder. Edited April 28, 2017 by tive29 Quote
Lee Mac Posted April 28, 2017 Posted April 28, 2017 Source of Brian's post: http://www.cadtutor.net/forum/showthread.php?79062-Save-a-copy-of-a-Dwg-file-to-two-locations&p=534285&viewfull=1#post534285 Quote
BrianTFC Posted April 28, 2017 Posted April 28, 2017 Lee, Sorry I would have put your name in the post but I forgot the post that it came from. Quote
Lee Mac Posted April 28, 2017 Posted April 28, 2017 (edited) BrianTFC said: Sorry I would have put your name in the post but I forgot the post that it came from. No worries - I just recognised the code. Try the following tive29: (defun c:dwgbackup ( / dir dst dwg src ) (setq dir "C:\\MyBackupFolder" ;; Backup Folder dir (vl-string-right-trim "\\" (vl-string-translate "/" "\\" dir)) dwg (getvar 'dwgname) ) (cond ( (zerop (getvar 'dwgtitled)) (princ "\nCurrent drawing is unsaved.") ) ( (not (or (vl-file-directory-p dir) (vl-mkdir dir))) (princ (strcat "\nUnable to create the directory \"" dir "\".")) ) ( (vl-file-copy (setq src (strcat (getvar 'dwgprefix) dwg)) (setq dst (LM:uniquefilename (strcat dir "\\" dwg))) ) ) ( (princ (strcat "\nUnable to copy \"" src "\" to \"" dst "\"."))) ) (princ) ) ;; Unique Filename - Lee Mac ;; Returns a filename suffixed with the smallest integer required for uniqueness (defun LM:uniquefilename ( fnm ) (if (findfile fnm) (apply '(lambda ( pth bse ext / tmp ) (setq tmp 1) (while (findfile (setq fnm (strcat pth bse "(" (itoa (setq tmp (1+ tmp))) ")" ext)))) ) (fnsplitl fnm) ) ) fnm ) (princ) Edited November 17, 2018 by Lee Mac Quote
tive29 Posted April 29, 2017 Author Posted April 29, 2017 (edited) hello Lee Mac. your lisp did make a backup but it is "saving" it to the current date when the lisp is run. Notice the date of the file copied to backup folder is todays date Below is what I am after. The date of the file "copied" to the backup folder is same as the original file. In short, make a copy of the file (not saving of the file) of the current open drawing to a backup folder. Edited April 29, 2017 by tive29 Quote
BIGAL Posted April 29, 2017 Posted April 29, 2017 You can not copy the dwg whilst its open if you want same date, so it makes sense that the sequence of events would be to use getfiled pick the file make a copy of it using vl-file-copy then open the file. Quote
tive29 Posted April 29, 2017 Author Posted April 29, 2017 (edited) BIGAL. I do not have option to select the file first as it is a xref drawing ,of a main drawing, which is in a sea of subfolders. I only know the main drawing folder location. The sequence of events prior to making a copy of the opening drawing is here: - open 1sty plan (main drawing) (it has multiple xrefs & nested xrefs inside) - Within the drawing Select tower 1 entity (which is a xref) & open xref. - When Tower 1 drawing opens. Within the drawing Select unit 5 (which is a xref) & open xref. - When unit 5 drawing opens, I will select the toilet entity(which is a xref) & open xref - When toilet drawing open, It is at this point I will need to backup this toilet drawing before doing any amendments. So I use the command to open that folder location or hopefully a lisp to directly make a copy. So I am unsure if your suggestions will help. Edited April 29, 2017 by tive29 Quote
BIGAL Posted April 29, 2017 Posted April 29, 2017 You may be able to copy the 3rd level xref whilst its open in the master dwg, no code but you can get to the xref list, its not something I have had to do. Autocad locks files so again it may not be possible without closing the master dwg doing the copy then reopen. Quote
tive29 Posted April 29, 2017 Author Posted April 29, 2017 You may be able to copy the 3rd level xref whilst its open in the master dwg, no code but you can get to the xref list, its not something I have had to do. Autocad locks files so again it may not be possible without closing the master dwg doing the copy then reopen. The above was an example. It can range from 2 to 7 xref levels deep. Main issue is not able to or difficult to locate the name of that xref drawing since the have many xref. So the easiest & fastest for me currently is to keep opening the xref drawings till I reach the drawing/level that I need. Quote
BIGAL Posted April 29, 2017 Posted April 29, 2017 This is close but I still think need the master dwg closed as it may be locking the xrefs from being copied. (defun c:dwgbackup ( / dir dst dwg src ) ;; Backup Folder (setq dir "C:\\Acadtemp") (setq dwg (strcat (getvar 'dwgprefix) (getvar 'dwgname))) (setq dest (strcat dir "\\" (getvar 'dwgname))) (setq fo (open "c:\\acadtemp\\dwgbackup.scr" "W")) (write-line "Close N" fo) (write-line (strcat "shell copy " dwg " " dest ) fo) (write-line (strcat "(alert " "file copied" ")") fo) (close fo) (command "script" "c:/acadtemp/dwgbackup.scr") ) (c:dwgbackup) Quote
tive29 Posted April 29, 2017 Author Posted April 29, 2017 This is close but I still think need the master dwg closed as it may be locking the xrefs from being copied. (defun c:dwgbackup ( / dir dst dwg src ) ;; Backup Folder (setq dir "C:\\Acadtemp") (setq dwg (strcat (getvar 'dwgprefix) (getvar 'dwgname))) (setq dest (strcat dir "\\" (getvar 'dwgname))) (setq fo (open "c:\\acadtemp\\dwgbackup.scr" "W")) (write-line "Close N" fo) (write-line (strcat "shell copy " dwg " " dest ) fo) (write-line (strcat "(alert " "file copied" ")") fo) (close fo) (command "script" "c:/acadtemp/dwgbackup.scr") ) (c:dwgbackup) Thanks. Will give it a shot once home. You mention to close the main drawing right? So all I need is to : 1) close the main dwg 2) go back to the xref dwg that is open 3) run the lisp. 4) a copy of the xref dwg will be copied to backup folder Am I right? Quote
tive29 Posted April 29, 2017 Author Posted April 29, 2017 Like this ? Yeah. Is it a lisp routine? Does it come in English? Would love to give it a try. Quote
maratovich Posted April 29, 2017 Posted April 29, 2017 (edited) If necessary, I can make any language. This program. Not Lisp Written on VB6. In the .exe archive, the program file. FileBackup 1.0.zip Edited April 29, 2017 by maratovich Quote
tive29 Posted April 29, 2017 Author Posted April 29, 2017 If necessary, I can make any language.This program. Not Lisp Written on VB6. In the .exe archive, the program file. Oh. Thanks but I may have problems install external programes. In my office they disable it. Unless I explain to them. Sad man. Hope BIGAL lisp works. Quote
maratovich Posted April 29, 2017 Posted April 29, 2017 Is not necessary installation. Put it on the desktop, and run it. Quote
tive29 Posted April 29, 2017 Author Posted April 29, 2017 This is close but I still think need the master dwg closed as it may be locking the xrefs from being copied. (defun c:dwgbackup ( / dir dst dwg src ) ;; Backup Folder (setq dir "C:\\Acadtemp") (setq dwg (strcat (getvar 'dwgprefix) (getvar 'dwgname))) (setq dest (strcat dir "\\" (getvar 'dwgname))) (setq fo (open "c:\\acadtemp\\dwgbackup.scr" "W")) (write-line "Close N" fo) (write-line (strcat "shell copy " dwg " " dest ) fo) (write-line (strcat "(alert " "file copied" ")") fo) (close fo) (command "script" "c:/acadtemp/dwgbackup.scr") ) (c:dwgbackup) BIGAL. when load the lisp, this error appears Cannot invoke (command) from *error* without prior call to (*push-error-using-command*).Converting (command) calls to (command-s) is recommended. Quote
Lee Mac Posted April 29, 2017 Posted April 29, 2017 your lisp did make a backup but it is "saving" it to the current date when the lisp is run.Notice the date of the file copied to backup folder is todays date Below is what I am after. The date of the file "copied" to the backup folder is same as the original file. In short, make a copy of the file (not saving of the file) of the current open drawing to a backup folder. The program I have posted does not save the current drawing prior to copying the drawing file; the modified date you are witnessing is a byproduct of using the vl-file-copy function to perform the copy. Quote
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.