See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: How to create a routine to batch process files or a directory

  1. #1
    I could stop if I wanted to
    Join Date
    2015-12
    Location
    Chesterfield, MI
    Posts
    405
    Login to Give a bone
    0

    Default 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

  2. #2
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,507
    Login to Give a bone
    0

    Default Re: How to create a routine to batch process files or a directory

    Quote Originally Posted by bcgatti View Post
    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
    Last edited by tedg; 2008-03-13 at 07:58 PM. Reason: Added more information

  3. #3
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,419
    Login to Give a bone
    0

    Default 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.
    C:> ED WORKING....


    LinkedIn

  4. #4
    I could stop if I wanted to
    Join Date
    2015-12
    Location
    Chesterfield, MI
    Posts
    405
    Login to Give a bone
    0

    Default 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

  5. #5
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,507
    Login to Give a bone
    1

    Default Re: How to create a routine to batch process files or a directory

    Quote Originally Posted by bcgatti View Post
    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!

  6. #6
    I could stop if I wanted to
    Join Date
    2015-12
    Location
    Chesterfield, MI
    Posts
    405
    Login to Give a bone
    0

    Default 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

  7. #7
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,507
    Login to Give a bone
    0

    Default Re: How to create a routine to batch process files or a directory

    Quote Originally Posted by bcgatti View Post
    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

  8. #8
    100 Club jsr13's Avatar
    Join Date
    2004-09
    Location
    Virginia - USA
    Posts
    134
    Login to Give a bone
    0

    Default 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.

  9. #9
    100 Club jsr13's Avatar
    Join Date
    2004-09
    Location
    Virginia - USA
    Posts
    134
    Login to Give a bone
    0

    Thumbs up 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.
    Attached Images Attached Images

  10. #10
    Woo! Hoo! my 1st post
    Join Date
    2016-11
    Posts
    1
    Login to Give a bone
    0

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

Page 1 of 2 12 LastLast

Similar Threads

  1. 2013: batch process for modifying multiple files
    By andres_t in forum AutoCAD General
    Replies: 2
    Last Post: 2012-12-21, 06:00 AM
  2. Replies: 2
    Last Post: 2012-08-08, 10:13 AM
  3. Batch Process files to a earlier version using Save AS
    By mserapiglia in forum CAD Management - General
    Replies: 5
    Last Post: 2009-01-24, 12:37 AM
  4. Batch routine to clean up Blocks within DWG files
    By george.arq in forum AutoLISP
    Replies: 3
    Last Post: 2007-01-25, 12:33 PM
  5. Replies: 3
    Last Post: 2006-08-04, 07:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •