Results 1 to 9 of 9

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

  1. #1
    I could stop if I wanted to
    Join Date
    2007-06
    Location
    Chesterfield, MI
    Posts
    379

    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
    AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    2,320

    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
    Ted
    ____________________________________________________________________________________
    AutoCAD 2012 - REVIT Structure 2012 - MicroStation V8i - Windows 7 Professional - (dabble with Inventor 2012)

  3. #3
    Forum Manager, Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    4,791

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

  4. #4
    I could stop if I wanted to
    Join Date
    2007-06
    Location
    Chesterfield, MI
    Posts
    379

    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
    AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    2,320

    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!
    Ted
    ____________________________________________________________________________________
    AutoCAD 2012 - REVIT Structure 2012 - MicroStation V8i - Windows 7 Professional - (dabble with Inventor 2012)

  6. #6
    I could stop if I wanted to
    Join Date
    2007-06
    Location
    Chesterfield, MI
    Posts
    379

    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
    AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    2,320

    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
    Ted
    ____________________________________________________________________________________
    AutoCAD 2012 - REVIT Structure 2012 - MicroStation V8i - Windows 7 Professional - (dabble with Inventor 2012)

  8. #8
    100 Club jsr13's Avatar
    Join Date
    2004-09
    Location
    Virginia - USA
    Posts
    130

    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.
    Jeff Rayhorn

    Sinclair Pratt Cameron, P.C.
    Consulting Structural Engineers
    Virginia Beach
    Virginia, USA

  9. #9
    100 Club jsr13's Avatar
    Join Date
    2004-09
    Location
    Virginia - USA
    Posts
    130

    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
    Jeff Rayhorn

    Sinclair Pratt Cameron, P.C.
    Consulting Structural Engineers
    Virginia Beach
    Virginia, USA

Similar Threads

  1. Batch Process files to a earlier version using Save AS
    By mserapiglia in forum CAD Management - General
    Replies: 5
    Last Post: 2009-01-23, 11:37 PM
  2. Batch process
    By idorion in forum Revit Architecture - API
    Replies: 1
    Last Post: 2008-07-22, 08:39 PM
  3. LISP routine to create PLT files from Layout tabs
    By Matt Mercer in forum AutoLISP
    Replies: 3
    Last Post: 2007-01-25, 01:30 PM
  4. Batch routine to clean up Blocks within DWG files
    By george.arq in forum AutoLISP
    Replies: 3
    Last Post: 2007-01-25, 11:33 AM
  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
  •