Author Topic: changing reference's bit archive  (Read 2154 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
changing reference's bit archive
« on: June 07, 2010, 05:38:34 PM »
Hi all..

we work here on several drawings who contain many different Xref, image, DGN, DWF etc..
our daily system backup is incermental, that mean that it take only the files who was changed during the day.
so if in some case, one of our server or HD crash or have promblem..
we need to recover the fully backup against the Daily one to retreive all the references who wasn't changed daily.

But,...not anymore with this lisp.
who use reactor on Save, Saveas, Close and Quit command and change all bits archive on each reference in the drawing
allowing daily backup to take also these files.

in that case....the daily backup can be restore more faster.

for who are interested.....
enjoy. !   :kewl:

Code: [Select]
;| ;;
Par Andrea Andreetti 2010-01-11 ;;
changement du bit archive d'un fichier ;;
par conséquant les XREF lorsque le dessin ;;
en contient et réagit avec un réacteur ;;
lié au fonctions de sauvegarde. ;;
Vérification Attribut du fichier ;;
;;
0 = No Attributes ;;
1 = Read-Only ;;
2 = Hidden ;;
4 = System Files ;;
32 = Archive bit set ;;
64 = Link or shortcut ;;
2048 = Compressed Files ;;
|;
;;


(vl-load-com)
(defun getbitarchive (file / fso)
  (setq fso (vla-getinterfaceobject
              (vlax-get-acad-object)
              "Scripting.FileSystemObject"
            )
  )
  (vlax-get-property (vlax-invoke-method fso 'getfile file)
                     'attributes
  )
)


(defun putbitarchive (bit file / fso)
  (setq fso (vla-getinterfaceobject
              (vlax-get-acad-object)
              "Scripting.FileSystemObject"
            )
  )
  (vlax-put-property (vlax-invoke-method fso 'getfile file)
                     'attributes
                     bit
  )
)





(defun get_all_xref_in_drawing ()
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (setq xrlst ())
  (setq xrflist ())
  (setq xrefpath nil)
  (setq blocks (vla-get-blocks doc))
  ;;XREF
  (vlax-for xref blocks
    (setq xrefpath nil)
    (if (eq :vlax-true (vla-get-isxref xref))
      (progn (setq xri_name (vlax-get xref 'name))
             (setq xri_type1 (vla-get-path xref))
             (if (vl-string-search ":\\" xri_type1)
               (setq xrefpath (findfile xri_type1))
               (progn (setq xrefpath (findfile
                                       (strcat (vl-filename-directory (getvar "DWGprefix"))
                                               "\\"
                                               (vl-string-left-trim ".\\" xri_type1)
                                       )
                                     )
                      )
                      (if (not xrefpath)
                        (setq xrefpath (findfile (vl-string-left-trim ".\\" xri_type1)))
                      )
               )
             )
             (if xrefpath
               (progn (setq g (ssget "X" (list '(0 . "INSERT") (cons 2 xri_name))))
                      (if g
                        (setq xrflist (append xrflist (list xrefpath)))
                      )
               )
             )
      )
    )
  )
  ;;IMAGE
  (setq imglist ())
  (setq layoutcol (vla-get-layouts doc))
  (vlax-for i layoutcol
    (vlax-for obj (vla-get-block i)
      (if (eq (vla-get-objectname obj) "AcDbRasterImage")
        (progn (setq i_path (vla-get-imagefile obj))
               (if (findfile i_path)
                 (setq imglist (append imglist (list i_path)))
               )
        )
      )
    )
  )
  ;;DWF et PDF et DGN
  (setq dwflist ())
  (setq layoutcol (vla-get-layouts doc))
  (vlax-for i layoutcol
    (vlax-for obj (vla-get-block i)
      (if (member (vla-get-objectname obj)
                  '("AcDbPdfReference" "AcDbDwfReference" "AcDbDgnReference")
          )
        (progn (setq dwf_file (vla-get-file obj))
               (if (findfile dwf_file)
                 (setq dwflist (append dwflist (list dwf_file)))
               )
        )
      )
    )
  )
  (setq xrflist (append xrflist imglist dwflist))
  (if blocks
    (progn (vlax-release-object blocks) (setq blocks nil))
  )
  (if layoutcol
    (progn (vlax-release-object layoutcol) (setq layoutcol nil))
  )
  (if xrflist
    (foreach i xrflist
      (if (= (getbitarchive i) 0)
        (putbitarchive 32 i)
      )
    )
  )
  (princ)
)







(defun *bitsarchive_onsave_reactor_start* (call-reactor sci /)
  (if (member (strcase (car sci)) (list "SAVEAS" "SAVE" "QSAVE" "CLOSE" "QUIT"))
    (get_all_xref_in_drawing)
  )
  (princ)
)


;;command WillStart
(if bitsarchive_onsave_reactor_start
  (progn (vlr-remove bitsarchive_onsave_reactor_start)
         (setq bitsarchive_onsave_reactor_start nil)
  )
)
(setq bitsarchive_onsave_reactor_start
       (vlr-command-reactor nil
                            '((:vlr-commandwillstart . *bitsarchive_onsave_reactor_start*)
                             )
       )
)
Keep smile...

Aerdvark

  • Guest
Re: changing reference's bit archive
« Reply #1 on: June 10, 2010, 04:08:45 PM »
Oh man how do you come up with these things?  :ugly:

I mean good, you know  ;-)

Andrea

  • Water Moccasin
  • Posts: 2372
Re: changing reference's bit archive
« Reply #2 on: June 14, 2010, 11:24:20 PM »
lol...thanks Aerdvark.

this idea come up when some of our IT talk about the system backup.

 :roll:
Keep smile...

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: changing reference's bit archive
« Reply #3 on: June 15, 2010, 05:38:48 AM »
Andrea

:oops: How to use :oops:

Andrea

  • Water Moccasin
  • Posts: 2372
Re: changing reference's bit archive
« Reply #4 on: July 20, 2010, 11:12:29 AM »
Andrea

:oops: How to use :oops:


Sorry for the Delay HasanCAD...
there is no command....just a reactor on Save, Saveas, Qsave, Close and Quit
allowing to check all references before and change bit archive of them.
Keep smile...