Author Topic: MOVEBAK  (Read 2390 times)

0 Members and 1 Guest are viewing this topic.

capsochist

  • Newt
  • Posts: 24
MOVEBAK
« on: February 24, 2020, 07:01:45 PM »
Hi there,

I am trying to place a 'MOVEBAK' line of code in my company acaddoc.lsp which points to a shared server backup location as I have not found a way to do this through the AutoCAD 'Open/Save' Options dialog.

Is there a line of code I could add to the below, so that the backup file would be saved into a folder with the current CAD users name (i.e, H:\Backup\CAD\username)? Username would need to be created by the code initiating the 'MOVEBAK' command since there are over 200 people in our firm.

Code - Auto/Visual Lisp: [Select]
  1. (command "MOVEBAK" "H:\Backup\CAD")

Thank you!

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: MOVEBAK
« Reply #1 on: February 24, 2020, 07:25:49 PM »
Code - Auto/Visual Lisp: [Select]
  1.     (setq dir
  2.       (strcat
  3.         "H:\\Backup\\CAD\\"
  4.         (getenv "UserName")
  5.       )
  6.     )
  7.   )
  8.   (setenv "AcetMoveBak" dir)
  9. )

capsochist

  • Newt
  • Posts: 24
Re: MOVEBAK
« Reply #2 on: February 25, 2020, 11:30:28 AM »
Code - Auto/Visual Lisp: [Select]
  1.     (setq dir
  2.       (strcat
  3.         "H:\\Backup\\CAD\\"
  4.         (getenv "UserName")
  5.       )
  6.     )
  7.   )
  8.   (setenv "AcetMoveBak" dir)
  9. )

Thank you so much! Would you mind providing comments so I can understand what is happening if I would like to make changes in the future?

For example, I am thinking of having the BAK files actually point to N:\_2019\1019200\CAD\BAK\Username

The location of this would need to pull the directory for each file based on the file location currently being worked in.

Thanks again!

ronjonp

  • Needs a day job
  • Posts: 7527
Re: MOVEBAK
« Reply #3 on: February 25, 2020, 12:20:42 PM »
See if you can follow this. Welcome to TheSwamp :)
Code - Auto/Visual Lisp: [Select]
  1. (defun c:bak (/ dir)
  2.   ;; Make the BAK subfolder in the working drawing
  3.   (vl-mkdir (strcat (setq dir (getvar 'dwgprefix)) "BAK"))
  4.   ;; Make the BAK\Username subfolder in the working drawing
  5.   (vl-mkdir (setq dir (strcat dir "\\BAK\\" (getenv "UserName"))))
  6.   ;; If the directory exists
  7.     ;; Set the environment variable
  8.     (setenv "AcetMoveBak" dir)
  9.   )
  10.   (princ)
  11. )
« Last Edit: February 25, 2020, 02:07:28 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: MOVEBAK
« Reply #4 on: February 25, 2020, 12:30:39 PM »
See if you can follow this. Welcome to TheSwamp :)
Code - Auto/Visual Lisp: [Select]
  1. (defun c:bak (/ dir)
  2.   ;; Make the BAK subfolder in the working drawing
  3.   (vl-mkdir (strcat (setq dir (getvar 'dwgprefix)) "BAK"))
  4.   ;; Make the BAK\Username subfolder in the working drawing
  5.   (vl-mkdir (setq dir (strcat d "BAK\\" (getenv "UserName"))))
  6.   ;; If the directory exists
  7.     ;; Set the environment variable
  8.     (setenv "AcetMoveBak" dir)
  9.   )
  10.   (princ)
  11. )

(vl-mkdir (setq dir (strcat dir "BAK\\" (getenv "UserName"))))  :-)

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: MOVEBAK
« Reply #5 on: February 25, 2020, 01:02:27 PM »
(vl-mkdir (setq dir (strcat dir "\\BAK\\" (getenv "UserName"))))
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

capsochist

  • Newt
  • Posts: 24
Re: MOVEBAK
« Reply #6 on: February 25, 2020, 01:38:36 PM »
See if you can follow this. Welcome to TheSwamp :)
Code - Auto/Visual Lisp: [Select]
  1. (defun c:bak (/ dir)
  2.   ;; Make the BAK subfolder in the working drawing
  3.   (vl-mkdir (strcat (setq dir (getvar 'dwgprefix)) "BAK"))
  4.   ;; Make the BAK\Username subfolder in the working drawing
  5.   (vl-mkdir (setq dir (strcat d "BAK\\" (getenv "UserName"))))
  6.   ;; If the directory exists
  7.     ;; Set the environment variable
  8.     (setenv "AcetMoveBak" dir)
  9.   )
  10.   (princ)
  11. )

Thank you, I think I follow the comment explanations, which are relatively straight forward. Before moving the backup, I just need to pull the directory as a variable so the function knows what sandbox to operate within. I also appreciate the warm welcome!

To be clear for anyone who finds this post useful, removing the general container for this code, allows it to run within the acaddoc.lsp
 
Code - Auto/Visual Lisp: [Select]
  1. ;; Make the BAK subfolder in the working drawing
  2.   (vl-mkdir (strcat (setq dir (getvar 'dwgprefix)) "BAK"))
  3.   ;; Make the BAK\Username subfolder in the working drawing
  4.   (vl-mkdir (setq dir (strcat dir "BAK\\" (getenv "UserName"))))
  5.   ;; If the directory exists
  6.     ;; Set the environment variable
  7.     (setenv "AcetMoveBak" dir)
  8.   )

without needing the following code:

Code - Auto/Visual Lisp: [Select]
  1. (LOAD "Z:/LD_CONFIG/LD_Lisp/BAK.lsp");; LOAD BAK COMMAND TO DIRECTORY
  2. (COMMAND "BAK");; CREATE AND EXECUTE BAK LOCATION THIS DWG

Please let me know if you feel this is bad practice for acaddoc.lsp so long as it is commented on clearly.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: MOVEBAK
« Reply #7 on: February 25, 2020, 02:06:25 PM »
(vl-mkdir (setq dir (strcat dir "\\BAK\\" (getenv "UserName"))))
Oops  :evil: .. fixed above.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7527
Re: MOVEBAK
« Reply #8 on: February 25, 2020, 02:16:06 PM »
See if you can follow this. Welcome to TheSwamp :)
Code - Auto/Visual Lisp: [Select]
  1. (defun c:bak (/ dir)
  2.   ;; Make the BAK subfolder in the working drawing
  3.   (vl-mkdir (strcat (setq dir (getvar 'dwgprefix)) "BAK"))
  4.   ;; Make the BAK\Username subfolder in the working drawing
  5.   (vl-mkdir (setq dir (strcat d "BAK\\" (getenv "UserName"))))
  6.   ;; If the directory exists
  7.     ;; Set the environment variable
  8.     (setenv "AcetMoveBak" dir)
  9.   )
  10.   (princ)
  11. )

Thank you, I think I follow the comment explanations, which are relatively straight forward. Before moving the backup, I just need to pull the directory as a variable so the function knows what sandbox to operate within. I also appreciate the warm welcome!

To be clear for anyone who finds this post useful, removing the general container for this code, allows it to run within the acaddoc.lsp
 
Code - Auto/Visual Lisp: [Select]
  1. ;; Make the BAK subfolder in the working drawing
  2.   (vl-mkdir (strcat (setq dir (getvar 'dwgprefix)) "BAK"))
  3.   ;; Make the BAK\Username subfolder in the working drawing
  4.   (vl-mkdir (setq dir (strcat dir "BAK\\" (getenv "UserName"))))
  5.   ;; If the directory exists
  6.     ;; Set the environment variable
  7.     (setenv "AcetMoveBak" dir)
  8.   )

without needing the following code:

Code - Auto/Visual Lisp: [Select]
  1. (LOAD "Z:/LD_CONFIG/LD_Lisp/BAK.lsp");; LOAD BAK COMMAND TO DIRECTORY
  2. (COMMAND "BAK");; CREATE AND EXECUTE BAK LOCATION THIS DWG

Please let me know if you feel this is bad practice for acaddoc.lsp so long as it is commented on clearly.

If you want to run this on startup you can call like so (c:bak). This will keep the 'dir' variable localized. I also added a check for drawing name and read-only.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:bak (/ dir)
  2.   ;; If the drawing has been named and is not read-only
  3.   (if (= 1 (getvar 'dwgtitled) (getvar 'writestat))
  4.     (progn ;; Make the BAK subfolder in the working drawing
  5.            (vl-mkdir (strcat (setq dir (getvar 'dwgprefix)) "BAK"))
  6.            ;; Make the BAK\Username subfolder in the working drawing
  7.            (vl-mkdir (setq dir (strcat dir "\\BAK\\" (getenv "UserName"))))
  8.            ;; If the directory exists
  9.            (if (vl-file-directory-p dir)
  10.              ;; Set the environment variable
  11.              (setenv "AcetMoveBak" dir)
  12.            )
  13.     )
  14.   )
  15.   (princ)
  16. )
  17. (c:bak)

Also .. the previous code you used had a typo in it. Use this post as your base.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC