Jump to content

make a copy of current open drawing & place it into a predetermine folder


tive29

Recommended Posts

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?

Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • tive29

    10

  • BIGAL

    4

  • Lee Mac

    4

  • maratovich

    3

Top Posters In This Topic

Posted Images

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)
)

Link to comment
Share on other sites

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 by tive29
Link to comment
Share on other sites

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 by Lee Mac
Link to comment
Share on other sites

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

Untitled.jpg

 

 

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.

Untitled2.jpg

Edited by tive29
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by tive29
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

attachment.php?attachmentid=61213&stc=1

 

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.

attachment.php?attachmentid=61214&stc=1

 

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...