Author Topic: Creating Directories and over-writing dwgs  (Read 5731 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Guest
Creating Directories and over-writing dwgs
« on: August 03, 2005, 02:34:08 PM »
Hello everyone,
I have been running a search for different ways of creating directories within ACAD and if the directory exists, to overwrite the dwgs within and / or delete them when necessary.

I've found a couple references but they are a little obscure (at least with as little as I know, they seem to me obscured)  :)

Anyways, could you mighty guro's drop some ideas as to the workings of searching for a directory, if it doesn't exist, create the directory.  If it does exist, report back what is in the directory.

Also, How to over write a dwg.  I have been using the expert variable, setting it to 4 so it doesn't prompt for over writing.  Can you show me a better way of doing this.

And then, I have a curiousity question.  Is this possible ???
Code: [Select]

  (if (/= (tblsearch "ucs" (strcat "ucstmp" dwgname)) nil)
    (command ".ucs" "d" "ucstmp*")
  )

I want to search for any USC names, if it finds any, then delete them.

Thanks guys.

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Creating Directories and over-writing dwgs
« Reply #1 on: August 03, 2005, 03:17:31 PM »
Check the vl-file-* functions and/or visit my homepage -> Free Stuff and search for 'VxDeleteFiles', 'VxMakeDirectory', etc.

Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

ronjonp

  • Needs a day job
  • Posts: 7529
Creating Directories and over-writing dwgs
« Reply #2 on: August 03, 2005, 03:27:51 PM »
I use this to create backup my drawings on every save.

Code: [Select]
;_____________________________________________________________________________
;;MAKES COPY OF DRAWING IN C:\AutoCAD-BAK
;_____________________________________________________________________________


(defun copydwg (/ destdir dwgdir *date* hour)
(if (not (wcmatch (getvar 'DWGNAME) "Drawing*.dwg"))
    (progn

   (defun *date* (/ curdate curtime)
     (setq   curdate (rtos (fix (getvar 'cdate)) 2 0)
      curtime (strcat (substr curdate 5 2) "-" (substr curdate 7 2) "-" (substr curdate 1 4)))
   )

(defun hour (/ ctime ampm stime)
  (setq ctime (rtos (rem (getvar 'cdate) 1) 2 6)
       ampm  (if (<= (atof (substr ctime 3 2)) 12) "AM" "PM")
       stime (strcat (substr ctime 3 2)))
)

               ;Makes C:\AutoCAD-BAK\currentdate\hour if it doesn't already exist

   (if (not
       (vl-file-directory-p (strcat "C:/AutoCAD-BAK/")))
       (vl-mkdir (strcat "C:/AutoCAD-BAK/"))
   )

   (if (not
       (vl-file-directory-p (strcat "C:/AutoCAD-BAK/" (*date*))))
       (vl-mkdir (strcat "C:/AutoCAD-BAK/" (*date*)))
   )


   (if (not
       (vl-file-directory-p (strcat "C:/AutoCAD-BAK/" (*date*) "/" (hour))))
       (vl-mkdir (strcat "C:/AutoCAD-BAK/" (*date*) "/" (hour)))
   )

               ;For some reason the files get huge if not deleted then saved on top of

   (if (findfile (strcat "C:/AutoCAD-BAK/" (*date*) "/" (hour) "/" (getvar 'dwgname)))
     (vl-file-delete (strcat "C:/AutoCAD-BAK/" (*date*) "/" (hour) "/" (getvar 'dwgname)))
   )

   (setq destdir (strcat "C:/AutoCAD-BAK/" (*date*) "/" (hour) "/" (getvar 'dwgname))
         dwgdir  (strcat (getvar 'dwgprefix) (getvar 'dwgname))
   )
   (vl-file-copy dwgdir destdir T)
      )
    )
  )
(copydwg)


;_____________________________________________________________________________
;;COMMAND REACTORS
;_____________________________________________________________________________


(vlr-command-reactor nil '((:vlr-commandEnded . endCommand)))

(defun endCommand (calling-reactor endcommandInfo / thecommandend)
(setq thecommandend (nth 0 endcommandInfo))
(cond
  ((= thecommandend "QSAVE") (copydwg))
  ((= thecommandend "SAVE") (copydwg))
)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

whdjr

  • Guest
Creating Directories and over-writing dwgs
« Reply #3 on: August 04, 2005, 11:23:53 AM »
This is an unfinished routine I was working on to do exactly what you are asking.  You it as a reference.  
Code: [Select]
(defun c:copyfolders (/ path)
;;;Returns the folder object.
  (defun get_folder_obj (msg)
    (vlax-invoke
      (vlax-get-or-create-object "Shell.Application")
      'browseforfolder
      0
      msg
      1
      ""
    )
  )
;;;Returns the folder path from the folder object.
  (defun get_folder_path (obj)
    (vla-get-path
      (vlax-invoke-method (vlax-invoke-method obj 'items) 'item)
    )
  )
;;;Recursive function to return all directories.
  (defun get_subs (folder / f)
    (mapcar '(lambda (x)
      (setq f (str_cat folder x))
      (cons f (apply 'append (get_subs f)))
    )
   (get_folders folder)
    )
  )
;;;Returns the folders from the supplied folder.
  (defun get_folders (path) (cddr (vl-directory-files path nil -1)))
;;;Joins the path a folder or a filename.
  (defun str_cat (path name) (strcat path "\\" name))
;;;Main Program
  (setq path ;(get_folder_path
      (get_folder_obj "Select Folder to copy Structure")
    ;)
  )
  (setq path2 ;(get_folder_path
     (copy_here
      (get_folder_obj "Select Folder location for new Folder Structure")
    )
  )
  ;(apply 'append (get_subs path))
  (princ)
)


(defun mkdir (obj)
  (vlax-invoke-method
    (vlax-invoke-method (vlax-invoke-method obj 'items) 'item)
    'copyhere
    path
  )
)

Hangman

  • Guest
Creating Directories and over-writing dwgs
« Reply #4 on: August 04, 2005, 04:48:20 PM »
Wow, ...
whdjr, that's a lot of stuff I don't understand, makes me think I'm miss'n something.   Nice but I have no idea how to finish it, I'm not proficient with vl, I kind of do a mix, mostly AutoLisp with a touch of vl here and there.  Someday I'll catch up with you though.

Ronjonp, Excellent.  Almost exactly what I was trying to find.  The only difference is that I need to set the directory at a variable.   It has to change with the current project number being used.
Code: [Select]

(if (not
       (vl-file-directory-p (strcat "C:/AutoCAD-BAK/")))
       (vl-mkdir (strcat "C:/AutoCAD-BAK/"))
   )

Instead of setting a hard coded directory  "C:/AutoCAD-BAK/", I need to be able to adjust with the project number like so:
Code: [Select]

  (setq cfpath (getvar "dwgprefix")
        cfname (getvar "dwgname")
        fpend "Bind\/"
        nfpath (strcat cfpath fpend)
        nfname (strcat nfpath cfname)
  )

Where nfpath is the directory being searched and Bind being the directory to create if it isn't there.
I like your code though, nice way of backing up the dwgs.

ronjonp

  • Needs a day job
  • Posts: 7529
Creating Directories and over-writing dwgs
« Reply #5 on: August 04, 2005, 07:11:14 PM »
So where is this project number stored? In the dwg name? Give an example of desired outcome for the path.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Hangman

  • Guest
Creating Directories and over-writing dwgs
« Reply #6 on: August 05, 2005, 06:10:04 PM »
My directory management goes as follows:

-Server:/2005 Drawings/05001/Bind
-Server:/2005 Drawings/05002/Bind
-Server:/2005 Drawings/05003/Bind ... etc.

-Server:/2004 Drawings/04001/Bind
-Server:/2004 Drawings/04002/Bind
-Server:/2004 Drawings/04003/Bind ... etc.

-Server:/Drawings/01001/Bind
-Server:/Drawings/02001/Bind
-Server:/Drawings/03001/Bind ... etc.

-Server:/Archives/00001/Bind
-Server:/Archives/99002/Bind
-Server:/Archives/98003/Bind ... etc.

These cover the main portion of it.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Creating Directories and over-writing dwgs
« Reply #7 on: December 20, 2023, 02:08:07 AM »
Thaks ronjonp for this usefull lisp

I am wondering is it able to save file when close the file to be sure the copy is last changes made in file.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Creating Directories and over-writing dwgs
« Reply #8 on: December 20, 2023, 08:49:40 AM »
Why not use a bat file:

bat file code below:
robocopy F:\Services Z:\Backup-ClientFiles\Services /e /mir /np /tee /log+:RoboCopyBackUpLog-Work.txt


example of some of the files updated within a directory and reported on:

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                             
-------------------------------------------------------------------------------

  Started : Tuesday, December 19, 2023 10:45:50 AM
   Source : F:\Covert\
     Dest : Z:\Backup-ClientFiles\Covert\

    Files : *.*
      
  Options : *.* /TEE /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /NP /R:1000000 /W:30

------------------------------------------------------------------------------

                      3   F:\Covert\
                      6   F:\Covert\Dodson\
                     30   F:\Covert\Dodson\archive\
                      8   F:\Covert\Dodson\keep\
                      5   F:\Covert\Dodson\markups\
                     11   F:\Covert\Dodson\pdf\
                     17   F:\Covert\Dodson\pdf\old\
                      9   F:\Covert\examples\
                     18   F:\Covert\examples\2050 Creekside Remodel\
                      1   F:\Covert\examples\archive\
                      1   F:\Covert\Template\

------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :        11         0        11         0         0         0
   Files :       109         0       109         0         0         0
   Bytes :  165.59 m         0  165.59 m         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00
   Ended : Tuesday, December 19, 2023 10:45:50 AM

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Creating Directories and over-writing dwgs
« Reply #9 on: December 21, 2023, 05:21:47 AM »
Why not use a bat file:
...
I modified the lisp and added to startup to make backup for each opened file in case of file lost for any reason (deleting by mistake from server and there is no Recycle Bin on server)
My colleague deleted a folder has 52 files by mistake Yesterday.

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: Creating Directories and over-writing dwgs
« Reply #10 on: December 21, 2023, 06:30:24 PM »
Reminds me of the old DOS "UN-Delete" I think it was part of Norton Utilities. Ok when you delete a file its not gone, rather its disk space is marked as free, so you can if you do not delay to long Un-delete files. A cheap tool compared to hours of work. HasanCAD  maybe look in your temp directory look for bak and sv$ files rename to DWG and see if can open. These get made if you have Autosave set.
A man who never made a mistake never made anything