Results 1 to 8 of 8

Thread: Custom Save command, save a copy of DWG file locally

  1. #1
    Certifiable AUGI Addict robert.1.hall72202's Avatar
    Join Date
    2004-07
    Location
    Detroit Michigan
    Posts
    2,508
    Login to Give a bone
    0

    Default Custom Save command, save a copy of DWG file locally

    Can the following code be modified to put the archived copy
    in a folder on the C: drive?

    I found this code on hot tip harry and I am entertaining different
    methods of backing up my cad files. I am having trouble depending
    on my IT department.

    Code:
    (DEFUN C:MRSAVE (/ path mrr flnm newname original)
    (setvar "CMDECHO" 0)
    (command "_.qsave")
    (setvar "filedia" 0)
    (setq path (getvar "DWGPREFIX"))
    (setq mrr "Mirror")
    (setq flnm (getvar "DWGNAME"))
    (setq original (strcat path flnm))
    (setq newname (strcat path mrr flnm))
      (if (null (findfile newname))
          (command "_.saveas" "" newname)
          (command "_.saveas" "" newname "y")
      )
    
    (command "_.saveas" "" original "y")
    (setvar "filedia" 1)
    (princ)
    )

  2. #2
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Custom Save command, save a copy of DWG file locally

    Code:
    (setq newname (strcat path mrr flnm))
    Change this line to the new path location (replace path with "c:\\")

  3. #3
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,804
    Login to Give a bone
    0

    Default Re: Custom Save command, save a copy of DWG file locally

    Quote Originally Posted by Robert.Hall
    I am entertaining different methods of backing up my cad files.
    Above and beyond the .BAK file that gets created?

    A quick way to make a duplicate of the current drawing is just to ._QSAVE twice. At that point, the BAK = the DWG.

    A couple of comments on the code you posted.

    1. It will fail if you run it on a new drawing that has never been saved
    2. There is no need to perform 3 saves (original, saveas, save original). Just use the ._SAVE command to accomplish the last two. Depending on file size, this could save you some time.

    Here is a suggestion that addresses those two items:

    Code:
      (DEFUN C:MRSAVE (/ newname)
       (setvar "CMDECHO" 0)
       (if (zerop (getvar "dwgtitled"))
     	(command "._qsave" (getstring "\n Enter drawing name: "))
     	(command "_.qsave")
       )
       (setvar "filedia" 0)
       (setq newname 
     		(strcat
     		  "C:\\"
     		  (getvar "DWGNAME")
     		  "-BAK"		  
     		)
       )  
       (if (findfile (strcat newname ".dwg"))
     	(command "_.save" newname "_Y")
     	(command "_.save" newname)
       )
       (setvar "filedia" 1)
       (princ)
     )
    Last edited by rkmcswain; 2007-01-24 at 02:14 PM.
    R.K. McSwain | CAD Panacea |

  4. #4
    Certifiable AUGI Addict robert.1.hall72202's Avatar
    Join Date
    2004-07
    Location
    Detroit Michigan
    Posts
    2,508
    Login to Give a bone
    0

    Default Re: Custom Save command, save a copy of DWG file locally

    Quote Originally Posted by rkmcswain
    Above and beyond the .BAK file that gets created?

    A quick way to make a duplicate of the current drawing is just to ._QSAVE twice. At that point, the BAK = the DWG.

    A couple of comments on the code you posted.

    1. It will fail if you run it on a new drawing that has never been saved
    2. There is no need to perform 3 saves (original, saveas, save original). Just use the ._SAVE command to accomplish the last two. Depending on file size, this could save you some time.
    Good point. Is there a way to set the file path in your routine?

  5. #5
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,804
    Login to Give a bone
    0

    Default Re: Custom Save command, save a copy of DWG file locally

    Quote Originally Posted by Robert.Hall
    Good point. Is there a way to set the file path in your routine?
    I updated the code in my earlier post.

    If you don't want to use the root of C:\ drive, just replace "C:\\" with your desired path.

    I also preferred appending "-BAK" on the end of the file, rather than prefixing it with "Mirror".

    Basically you can alter the (setq newname.... line to make the "copy" filename whatever you want.
    R.K. McSwain | CAD Panacea |

  6. #6
    100 Club Mohmed Zuber's Avatar
    Join Date
    2005-08
    Location
    Bharuch in India
    Posts
    136
    Login to Give a bone
    0

    Default Re: Custom Save command, save a copy of DWG file locally

    Quote Originally Posted by Robert.Hall
    Can the following code be modified to put the archived copy
    in a folder on the C: drive?

    I found this code on hot tip harry and I am entertaining different
    methods of backing up my cad files. I am having trouble depending
    on my IT department.
    Oh! my goodness, you are discussing my program an I am unaware about it. Carry on fruitful discussion is going on.
    Last edited by Mohmed Zuber; 2007-01-24 at 03:35 PM. Reason: forget to unquote Roberts query

  7. #7
    Certifiable AUGI Addict robert.1.hall72202's Avatar
    Join Date
    2004-07
    Location
    Detroit Michigan
    Posts
    2,508
    Login to Give a bone
    0

    Default Re: Custom Save command, save a copy of DWG file locally

    Cool! You had a great idea when you put it together.

  8. #8
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: Custom Save command, save a copy of DWG file locally

    This reactor, copy your previously Saved -or ExitSaved drawing to ( in this case ) the folder "C:\\DwgBackup"
    the name of the file will be "Bak_Drawing3.dwg" if the parent drawing is "Drawing3.dwg"
    Code:
    (vl-load-com)
    (defun When_Saving_And_Copy_Drawing_Function (ReactorArg ObjListArg / MyBackupPath )
      (setq MyBackupPath "C:\\DwgBackup" ) ;; <-- Your EXISTING Backup Folder !
      (vl-file-delete (strcat MyBackupPath "\\Bak_" (getvar "DWGNAME" )) ) ;; Erase old "Bak_" copy if exist, then
      (vl-file-copy (findfile (cadr ObjListArg )) (strcat MyBackupPath "\\Bak_" (getvar "DWGNAME" )) nil ) ;; create a new "Bak_" copy
    )
    (setq When_Saving_And_Copy_Drawing_Reactor (vlr-dwg-reactor nil '((:vlr-saveComplete . When_Saving_And_Copy_Drawing_Function ))) )
    To stop the reactor use:
    Code:
    (vlr-remove When_Saving_And_Copy_Drawing_Reactor ) ; Remove the reactor
    (setq When_Saving_And_Copy_Drawing_Reactor nil )   ; Clear / assign nil to the reactor
    (setq When_Saving_And_Copy_Drawing_Function nil )  ; Clear / assign nil to the function
    : ) Happy Computing !

    kennet

Similar Threads

  1. 2015: Save a Copy as file extension
    By RRF688245 in forum Inventor - General
    Replies: 3
    Last Post: 2015-01-07, 08:22 PM
  2. 2015: Save As & save new command will not work
    By Doug in forum Revit Architecture - General
    Replies: 6
    Last Post: 2014-06-10, 01:25 PM
  3. MAKE BOLTED CONNECTION "SAVE" ACTUALLY SAVE THE FILE
    By Wish List System in forum Inventor Wish List
    Replies: 0
    Last Post: 2012-12-17, 08:56 PM
  4. Save a Copy of file
    By swatson19d in forum AutoCAD Map 3D - General
    Replies: 3
    Last Post: 2006-08-01, 04:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •