View Full Version : Purge & Audit all drawing files in a folder
rhayes.99001
2007-05-10, 08:00 PM
Is there a Lisp Routine that will do a purge and audit on an entire folder of drawings.?
I am looking for a quick way to clean a folder to archive drawings...
I am using ADT 05'
kennet.sjoberg
2007-05-10, 08:20 PM
You can use this LINK (http://forums.augi.com/showthread.php?t=14243#post88722) to make a script file and batch run everything in a directory.
just use the commands you want . . .
(princ "._zoom ext \n" File#1 )
(princ "._-layer s 0 \n" File#1 )
(princ "close Yes or No \n" File#1 )
: ) Happy Computing !
kennet
john.curschmann
2007-06-19, 12:01 PM
Supposedly there's a "Building Solutions Applet of the month" VREZaudit, but i can't find the link they say is on Subscription Center page
Robert.Hall
2007-06-19, 12:37 PM
Nice idea here.
I have my save command setup to do
a purge and zoom before I close the drawing
I am working on. Slows down cad, but it works.
kpblc2000
2007-06-19, 01:12 PM
> Robert.Hall : do you use command or docmanager reactor?
Robert.Hall
2007-06-19, 05:33 PM
I am using the following macro:
^C^C-layer;set;0;;_zoom;e;-purge;a;;n;-purge;a;;n;-purge;a;;n;audit;y;qsave;close
Gets the job done, however, it takes a few seconds.
kpblc2000
2007-06-19, 06:34 PM
Based on http://www.autocad.ru/cgi-bin/f1/board.cgi?t=31023zx and http://www.autocad.ru/cgi-bin/f1/board.cgi?t=28195cT :
;|
Based on CADALYST 03/05 Tip2023: PurgeFiles.lsp Directory Clean Up (c) Andrzej Gumula
[c]2004 Andrzej Gumula, Katowice, Poland
e-mail: a.gumula@wp.pl
|;
(vl-load-com)
(defun dofile (curdoc)
(vla-put-activelayer curdoc (vla-item (vla-get-layers curdoc) "0"))
(vl-catch-all-apply '(lambda () (vla-zoomall (vlax-get-acad-object))))
(repeat 4 (vla-purgeall curdoc))
) ;_ end of defun
(defun c:dofile (/ fileslist subdir files file)
(defun getfolder (/ dir item path)
(cond
((setq dir
(vlax-invoke
(vlax-get-or-create-object "Shell.Application")
'browseforfolder
0
"Select folder with DWG files:"
1
""
) ;_ end of vlax-invoke
) ;_ end of setq
(cond
((not (vl-catch-all-error-p
(vl-catch-all-apply 'vlax-invoke-method (list dir 'items))
) ;_ end of vl-catch-all-error-p
) ;_ end of not
(setq item (vlax-invoke-method
(vlax-invoke-method dir 'items)
'item
) ;_ end of vlax-invoke-method
) ;_ end of setq
(setq path (vla-get-path item))
(if
(not (member (substr path (strlen path) 1) (list "/" "\\")))
(setq path (strcat path "\\"))
) ;_ end of if
)
) ;_ end of cond
)
) ;_ end of cond
path
) ;_ end of defun
(defun vl-findfile (location / dirlist path allpath)
(makedirlist location)
(setq dirlist (cons location dirlist))
(foreach elem dirlist
(if (setq path (vl-directory-files elem "*.dwg"))
(foreach item path
(setq allpath (cons (strcat elem "/" item) allpath))
) ;_ end of foreach
) ;_ end of if
) ;_ end of foreach
(reverse allpath)
) ;_ end of defun
(defun makedirlist (arg / tmplist)
(setq tmplist (cddr (vl-directory-files arg nil -1)))
(cond (tmplist
(setq dirlist (append
dirlist
(mapcar '(lambda (z) (strcat arg "/" z)) tmplist)
) ;_ end of append
) ;_ end of setq
(foreach item tmplist (makedirlist (strcat arg "/" item)))
)
) ;_ end of cond
) ;_ end of defun
(setq *err-list* nil)
(if (not filesystemobject)
(setq filesystemobject
(vla-getinterfaceobject
(vlax-get-acad-object)
"Scripting.FileSystemObject"
) ;_ end of vla-getInterfaceObject
) ;_ end of setq
) ;_ end of if
(cond
((= (getvar "SDI") 0)
(cond
((setq dwgpath (getfolder))
(initget 1 "Yes No")
(setq
subdir (cond
((getkword "\nInclude subdirectories? [Yes/No]: "))
(t "Yes")
) ;_ end of cond
) ;_ end of setq
(if (equal subdir "Yes")
(setq files
(vl-findfile (substr dwgpath 1 (1- (strlen dwgpath))))
) ;_ end of setq
(setq files (mapcar '(lambda (x) (strcat dwgpath x))
(vl-directory-files dwgpath "*.dwg" 1)
) ;_ end of mapcar
) ;_ end of setq
) ;_ end of if
(setq files (mapcar 'strcase files))
(cond
(files
(vlax-for & (vla-get-documents (vlax-get-acad-object))
(setq fileslist
(cons (strcase (vla-get-fullname &)) fileslist)
) ;_ end of setq
) ;_ end of vlax-for
(foreach & files
(cond
((not (member & fileslist))
(cond
((/= (logand (vlax-get-property
(vlax-invoke-method
filesystemobject
'getfile
&
) ;_ end of vlax-invoke-method
'attributes
) ;_ end of vlax-get-property
1
) ;_ end of logand
1
) ;_ end of /=
(cond
((setq file
(vla-open (vla-get-documents
(vlax-get-acad-object)
) ;_ end of vla-get-documents
&
) ;_ end of vla-open
) ;_ end of setq
(prompt
(strcat "\nProcessing file" & ". Please wait...")
) ;_ end of prompt
(dofile file)
(prompt (strcat "\nSave and close " &))
(vla-save file)
(vla-close file)
(vlax-release-object file)
)
(t
(prompt
(strcat
"\nCannot open "
&
"\nDrawing file was created by an incompatible version. "
) ;_ end of strcat
) ;_ end of prompt
)
) ;_ end of cond
)
(t (prompt (strcat & " is read-only. Purge canceled. ")))
) ;_ end of cond
)
(t (prompt (strcat & " is open now. Purge canceled. ")))
) ;_ end of cond
) ;_ end of foreach
)
(t (prompt "\nNothing files found to purge. "))
) ;_ end of cond
)
(t (prompt "\nNothing selected. "))
) ;_ end of cond
)
(t (prompt "\nThe routine is not available in SDI mode. "))
) ;_ end of cond
(princ)
) ;_ end of defun
(prompt "\n===To start press DOFILE within command prompt===")
(princ)
Auditing won't works using ObjectDBX interface.
gilsoto13
2009-08-18, 09:10 PM
Based on http://www.autocad.ru/cgi-bin/f1/board.cgi?t=31023zx and http://www.autocad.ru/cgi-bin/f1/board.cgi?t=28195cT :
;|
Based on CADALYST 03/05 Tip2023: PurgeFiles.lsp Directory Clean Up (c) Andrzej Gumula
[c]2004 Andrzej Gumula, Katowice, Poland
e-mail: a.gumula@wp.pl
|;
(vl-load-com)
(defun dofile (curdoc)
(vla-put-activelayer curdoc (vla-item (vla-get-layers curdoc) "0"))
(vl-catch-all-apply '(lambda () (vla-zoomall (vlax-get-acad-object))))
(repeat 4 (vla-purgeall curdoc))
) ;_ end of defun
(defun c:dofile (/ fileslist subdir files file)
(defun getfolder (/ dir item path)
(cond
((setq dir
(vlax-invoke
(vlax-get-or-create-object "Shell.Application")
'browseforfolder
0
"Select folder with DWG files:"
1
""
) ;_ end of vlax-invoke
) ;_ end of setq
(cond
((not (vl-catch-all-error-p
(vl-catch-all-apply 'vlax-invoke-method (list dir 'items))
) ;_ end of vl-catch-all-error-p
) ;_ end of not
(setq item (vlax-invoke-method
(vlax-invoke-method dir 'items)
'item
) ;_ end of vlax-invoke-method
) ;_ end of setq
(setq path (vla-get-path item))
(if
(not (member (substr path (strlen path) 1) (list "/" "\\")))
(setq path (strcat path "\\"))
) ;_ end of if
)
) ;_ end of cond
)
) ;_ end of cond
path
) ;_ end of defun
(defun vl-findfile (location / dirlist path allpath)
(makedirlist location)
(setq dirlist (cons location dirlist))
(foreach elem dirlist
(if (setq path (vl-directory-files elem "*.dwg"))
(foreach item path
(setq allpath (cons (strcat elem "/" item) allpath))
) ;_ end of foreach
) ;_ end of if
) ;_ end of foreach
(reverse allpath)
) ;_ end of defun
(defun makedirlist (arg / tmplist)
(setq tmplist (cddr (vl-directory-files arg nil -1)))
(cond (tmplist
(setq dirlist (append
dirlist
(mapcar '(lambda (z) (strcat arg "/" z)) tmplist)
) ;_ end of append
) ;_ end of setq
(foreach item tmplist (makedirlist (strcat arg "/" item)))
)
) ;_ end of cond
) ;_ end of defun
(setq *err-list* nil)
(if (not filesystemobject)
(setq filesystemobject
(vla-getinterfaceobject
(vlax-get-acad-object)
"Scripting.FileSystemObject"
) ;_ end of vla-getInterfaceObject
) ;_ end of setq
) ;_ end of if
(cond
((= (getvar "SDI") 0)
(cond
((setq dwgpath (getfolder))
(initget 1 "Yes No")
(setq
subdir (cond
((getkword "\nInclude subdirectories? [Yes/No]: "))
(t "Yes")
) ;_ end of cond
) ;_ end of setq
(if (equal subdir "Yes")
(setq files
(vl-findfile (substr dwgpath 1 (1- (strlen dwgpath))))
) ;_ end of setq
(setq files (mapcar '(lambda (x) (strcat dwgpath x))
(vl-directory-files dwgpath "*.dwg" 1)
) ;_ end of mapcar
) ;_ end of setq
) ;_ end of if
(setq files (mapcar 'strcase files))
(cond
(files
(vlax-for & (vla-get-documents (vlax-get-acad-object))
(setq fileslist
(cons (strcase (vla-get-fullname &)) fileslist)
) ;_ end of setq
) ;_ end of vlax-for
(foreach & files
(cond
((not (member & fileslist))
(cond
((/= (logand (vlax-get-property
(vlax-invoke-method
filesystemobject
'getfile
&
) ;_ end of vlax-invoke-method
'attributes
) ;_ end of vlax-get-property
1
) ;_ end of logand
1
) ;_ end of /=
(cond
((setq file
(vla-open (vla-get-documents
(vlax-get-acad-object)
) ;_ end of vla-get-documents
&
) ;_ end of vla-open
) ;_ end of setq
(prompt
(strcat "\nProcessing file" & ". Please wait...")
) ;_ end of prompt
(dofile file)
(vla-AuditInfo File T)
(prompt (strcat "\nSave and close " &))
(vla-save file)
(vla-close file)
(vlax-release-object file)
)
(t
(prompt
(strcat
"\nCannot open "
&
"\nDrawing file was created by an incompatible version. "
) ;_ end of strcat
) ;_ end of prompt
)
) ;_ end of cond
)
(t (prompt (strcat & " is read-only. Purge canceled. ")))
) ;_ end of cond
)
(t (prompt (strcat & " is open now. Purge canceled. ")))
) ;_ end of cond
) ;_ end of foreach
)
(t (prompt "\nNothing files found to purge. "))
) ;_ end of cond
)
(t (prompt "\nNothing selected. "))
) ;_ end of cond
)
(t (prompt "\nThe routine is not available in SDI mode. "))
) ;_ end of cond
(princ)
) ;_ end of defun
(prompt "\n===To start press DOFILE within command prompt===")
(princ)
Auditing won't works using ObjectDBX interface.
It needed the audit command, so I added it, check above code
(vla-AuditInfo File T)
kpblc2000
2009-08-18, 09:48 PM
AuditInfo method works only on current (active) document.
gilsoto13
2009-08-24, 03:43 AM
AuditInfo method works only on current (active) document.
Well I guess it is ok to add it that way, because I used it on a bunch of files and it worked..
The bad thing is that this lisp stucks when opening a damaged drawing or trying to open a file that need recovery... the that file needs to be removed from the directory or open it using recover and audit inside and saving it manually to use the batch process again.
but It works... I just finished using it for a 5,000 files directory, the lisp stopped about 30 times... but It really audited all the files... I made sure of it.
Davie 73
2009-08-24, 08:34 AM
I use Hurricane for most batch scripting. Comes with quite a few basic lisps/scripts.
http://www.74mph.com/
Crackin wee program.
alanjt
2009-08-24, 04:21 PM
scriptpro was written by autodesk (hasn't been updated in years, but still works, except for plotting on versions after 04 or 05).
ccowgill
2009-08-24, 07:25 PM
scriptpro was written by autodesk (hasn't been updated in years, but still works, except for plotting on versions after 04 or 05).
last I heard, it doesnt work for 64bit AutoCAD.
alanjt
2009-08-24, 07:33 PM
last I heard, it doesnt work for 64bit AutoCAD.
yeah, it was written for the 32 bit age. i wasn't even thinking about that (we're still running 32 bit machines, so i still act like a caveman).
worth mentioning though and thank for the info.
renmanz
2009-09-21, 08:01 PM
this is great when turning over CAD files to another company, but would it be posible to also add something to Convert all Dynamic blocks to anonymous blocks which will disable the Dynamic features.
Example I found:
(defun c:ConvertDyn (/ actDoc)
(vl-load-com)
(setq actDoc
(vla-get-ActiveDocument
(vlax-get-acad-object)
) ;_ end_vla-get-ActiveDocument
) ;_ end_setq
(vla-startundomark actDoc)
(foreach x (vl-remove-if
'listp
(mapcar 'cadr (ssnamex (ssget "x" '((0 . "INSERT")))))
) ;_ end_vl-remove-if
(if (equal (vla-get-IsDynamicBlock (vlax-ename->vla-object x))
:vlax-true
) ;_ end_equal
(vla-ConvertToAnonymousBlock (vlax-ename->vla-object x))
) ;_ end_if
) ;_ end_foreach
(vla-endundomark actDoc)
(princ)
) ;_ end_defun
;;(princ "\nType ConvertDyn in command line to start lisp")
gilsoto13
2009-10-05, 07:58 PM
this is great when turning over CAD files to another company, but would it be posible to also add something to Convert all Dynamic blocks to anonymous blocks which will disable the Dynamic features.
Example I found:
(defun c:ConvertDyn (/ actDoc)
(vl-load-com)
(setq actDoc
(vla-get-ActiveDocument
(vlax-get-acad-object)
) ;_ end_vla-get-ActiveDocument
) ;_ end_setq
(vla-startundomark actDoc)
(foreach x (vl-remove-if
'listp
(mapcar 'cadr (ssnamex (ssget "x" '((0 . "INSERT")))))
) ;_ end_vl-remove-if
(if (equal (vla-get-IsDynamicBlock (vlax-ename->vla-object x))
:vlax-true
) ;_ end_equal
(vla-ConvertToAnonymousBlock (vlax-ename->vla-object x))
) ;_ end_if
) ;_ end_foreach
(vla-endundomark actDoc)
(princ)
) ;_ end_defun
;;(princ "\nType ConvertDyn in command line to start lisp")
Well... that code only accepts vla commands... lisp commands can be added to a batch process trough another lisp... I personally can do it now by using the Batch.lsp and and 2 other lisp files, 1 for your process and 1 for loading your first lisp, a starting script may help you adding orders to your lisp and then you can go trough many files and convert all dynamic blocks to annonymous.. need more help? let me know.
krushert
2010-03-29, 06:53 PM
Based on http://www.autocad.ru/cgi-bin/f1/board.cgi?t=31023zx and http://www.autocad.ru/cgi-bin/f1/board.cgi?t=28195cT :
;|
Based on CADALYST 03/05 Tip2023: PurgeFiles.lsp Directory Clean Up (c) Andrzej Gumula
[c]2004 Andrzej Gumula, Katowice, Poland
e-mail: a.gumula@wp.pl
|;
(vl-load-com)
(defun dofile (curdoc)
(vla-put-activelayer curdoc (vla-item (vla-get-layers curdoc) "0"))
(vl-catch-all-apply '(lambda () (vla-zoomall (vlax-get-acad-object))))
(repeat 4 (vla-purgeall curdoc))
) ;_ end of defun
(defun c:dofile (/ fileslist subdir files file)
< snip>
) ;_ end of defun
(prompt "\n===To start press DOFILE within command prompt===")
(princ)Auditing won't works using ObjectDBX interface.
For Some reason, this code is not allowing me to use any Lisp commands after the this routine finishes. I can use core commands no problem.
I am getting this at the command line.
AecRcpLispSupport::getArgIgnore() got null."
Ehsan
2010-04-28, 07:34 AM
Using the same routine can i put one function which can collect all the xref attached to all the drawings and write it to a text file.
the function is given below also tell me where to add this function.
thanks
(defun C:Get_Xref_Paths (/ fopen outputfile jbActiveDoc)
(vl-load-com)
(defun *error*(msg)(if fopen (close fopen)))
;;;; Creat the Drectory if it do not exist
(if (not (vl-file-directory-p "D:\\CAD_Xref_Files\\"))(vl-mkdir "D:\\CAD_Xref_Files\\"))
(setq outputfile (strcat "D:\\CAD_Xref_Files\\" "Xref_Dwgs_Path" ".txt"))
(if (findfile outputfile)
(setq fopen (open outputfile "a"))
(setq fopen (open outputfile "w"))
)
(setq jbActiveDoc (vlax-get-property (vlax-get-acad-object) 'activedocument))
(vlax-for X (vla-get-blocks jbActiveDoc)(if (= (vlax-get-property X "IsXRef") :vlax-true)
(write-line (vla-get-path X) fopen)))
(write-line "-------------------" fopen)
(close fopen)
;(startapp "notepad.exe" outputfile)
(princ)
)
Powered by vBulletin® Version 4.1.11 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.