PDA

View Full Version : How to create a routine to batch process files or a directory


bcgatti
2008-03-13, 05:23 PM
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

tedg
2008-03-13, 09:44 PM
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

Ed Jobe
2008-03-13, 09:58 PM
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.

bcgatti
2008-03-13, 10:03 PM
Ed and tedg,

Thanks for the feedback. I'll take a look at ScriptPro and see what I can do.

Brett

tedg
2008-03-13, 10:26 PM
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"

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:

(load "C:\\lisp\\ted_purge\\TED_PURGE.lsp")
P6
QUIT
YAnd this is just the simple purge routine "Ted_Purge.lsp" you would use your routine for your purpose:

(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!

bcgatti
2008-03-14, 02:53 PM
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

tedg
2008-03-14, 04:13 PM
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:

jsr13
2008-04-10, 05:16 AM
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.

jsr13
2008-04-10, 06:15 AM
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/item?siteID=123112&id=4091678&linkID=9240618

There are two downloads: one for ACAD 2004 thru 2006 and one for v2007 and later.

Again: very good thread.