How to create a routine to batch process files or a directory
I have a lisp routine (that does some drawing file cleanup – recover, purge, etc…) which I need to periodically run against certain files in multiple directories. These are typically files that are exported from other CAD packages and each time that we get a new batch they need a little bit of cleanup.
Is there any way to incorporate this lisp routine into a program or a different routine so that it will run without opening each file individually and / or without creating a script file each time that I want to perform it? The file names will vary each time that I have to run this routine so I was hoping to be able to “drag and drop” a group of files onto an executable file icon or some other method where I could use Explorer to pick random files in a directory and apply the commands to the files. It would also be acceptable to run the routine / program against an entire directory – but once again, I do not want to have to build a file list each time that I need to perform this command.
Creating Lsp files is about as far as my current knowledge will take me. I have played around with AutoHotKey a little and I could not figure out how to accomplish what I want to accomplish using their software.
Any nudge in the right direction would be greatly appreciated.
Brett
Re: How to create a routine to batch process files or a directory
Quote:
Originally Posted by
bcgatti
I have a lisp routine (that does some drawing file cleanup – recover, purge, etc…) which I need to periodically run against certain files in multiple directories. These are typically files that are exported from other CAD packages and each time that we get a new batch they need a little bit of cleanup.
Is there any way to incorporate this lisp routine into a program or a different routine so that it will run without opening each file individually and / or without creating a script file each time that I want to perform it? The file names will vary each time that I have to run this routine so I was hoping to be able to “drag and drop” a group of files onto an executable file icon or some other method where I could use Explorer to pick random files in a directory and apply the commands to the files. It would also be acceptable to run the routine / program against an entire directory – but once again, I do not want to have to build a file list each time that I need to perform this command.
Creating Lsp files is about as far as my current knowledge will take me. I have played around with AutoHotKey a little and I could not figure out how to accomplish what I want to accomplish using their software.
Any nudge in the right direction would be greatly appreciated.
Brett
I don't think you can do this without at least running a script (which runs outside of AutoCAD) to open each dwg and run the routine save and close it. I'm pretty sure it can be done but I don't know how to do it.
I think you need to create a "batch file" as well which calls out the script which will run the lisp. It's been a while since I've done anything like that, but maybe someone with more programming experience can help.
So to recap, I think you'll need a .BAT file, an .SCR file and your .LSP file to work together and do the job.
good luck
Re: How to create a routine to batch process files or a directory
ScriptPro can do that. It is downloadable from Subscription Center. You just create a list of files to run the script (a script can contain/run lisp) on.
Re: How to create a routine to batch process files or a directory
Ed and tedg,
Thanks for the feedback. I'll take a look at ScriptPro and see what I can do.
Brett
Re: How to create a routine to batch process files or a directory
Quote:
Originally Posted by
bcgatti
Ed and tedg,
Thanks for the feedback. I'll take a look at ScriptPro and see what I can do.
Brett
I was able to dig up what I was talking about with the batch file, script file and lisp file.
If you don't want to go the ScriptPro route.
This is an example, so you will need to add your file paths and programs accordingly:
This is the batch file named "Ted_Purge.bat" it starts AutoCAD, opens each drawing in the folder "C:\lisp\Ted_Purge" and runs the script file "Ted_Purge.scr"
Code:
FOR %%f in (C:\"lisp"\"ted_purge"\*.dwg) do start /wait C:\"Program Files"\"Autodesk Architectural Desktop 2006"\acad.exe "%%f" /b "C:\lisp\ted_purge\ted_purge.scr"
This is the script file named "Ted_Purge.scr" named above which loads and runs the "Ted_Purge.lsp" routine and then saves and quits:
Code:
(load "C:\\lisp\\ted_purge\\TED_PURGE.lsp")
P6
QUIT
Y
And this is just the simple purge routine "Ted_Purge.lsp" you would use your routine for your purpose:
Code:
(defun c:p6 ()
(setq ce (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "layer" "s" "0" "")
(command "zoom" "e" "zoom" ".9x" )
(repeat 3
(command "._purge" "_A" "*" "_N")
(command "purge" "regapps" "" "n"))
(setvar "cmdecho" ce)
(command "_qsave")
(princ)
)
Hope it helps!
Re: How to create a routine to batch process files or a directory
tedg,
Thanks for the batch and script information. That was exactly what I was looking for. I have used your example to get things up and running exactly as I had hoped.
I am still going to take a look at ScriptPro for future reference when this type of request comes up.
Brett
Re: How to create a routine to batch process files or a directory
Quote:
Originally Posted by
bcgatti
tedg,
Thanks for the batch and script information. That was exactly what I was looking for. I have used your example to get things up and running exactly as I had hoped.
I am still going to take a look at ScriptPro for future reference when this type of request comes up.
Brett
Glad I could help :beer:
Re: How to create a routine to batch process files or a directory
Very helpful thread, guys. I'm having a bit of a glitch, though. I have created the same files as stated and run the bat file, but it only opens the first file, processes it, and closes autocad leaving the cmd window open. No more files are opened/processed.
Any ideas why it isn't going on to the next drawing file?
Thanks in advance.
1 Attachment(s)
Re: How to create a routine to batch process files or a directory
I think I found part of the problem in the attached screenshot. Me thinks there was a loop (or something) somewhere.
So I decided to go the route of Script Pro. I had forgotten about it but it has been around for years (maybe even pre-2000?). It works great.
FYI for any others interested: http://usa.autodesk.com/adsk/servlet...linkID=9240618
There are two downloads: one for ACAD 2004 thru 2006 and one for v2007 and later.
Again: very good thread.
Re: How to create a routine to batch process files or a directory
I am also attempting to run a routine on multiple drawings in a target directory. I had found and modified a script to adjust the lineweights and colors, no issues. But trying to add in a -laydel command it stops if the layer is not present. Or at least that is my guess. Regardless I found a LSP that works flawlessly and much faster. My question is how do I incorporate this LSP routine into a script and point it at a target directory? (there are hundreds of drawings in this directory and the names will change eventually so would prefer to use a wild card or *file* instead of the filename.
Here is the LSP that works very well. Now i just want to put this into a script so it will run on the target directory.
Code:
(defun c:demo nil
(foreach lay '("G-ANNO-TEXT" "M-HVAC-DUCT-IDEN" "M-HVAC-CDFF-IDEN" "A-ANNO-NOTE" "A-DETL" "G-ANNO-REVC-IDEN" "A-ANNO-MATC")
(if (tblobjname "layer" lay)
(command "_.-laydel" "_N" lay "" "_Y")
)
)
(princ)
)
Thank you for your help!!!