Batch Process Strategy

Discussion in 'AutoCAD' started by steveing, Aug 12, 2004.

  1. steveing

    steveing Guest

    Curious as to how you accomodate for batch processing?

    The 2 different ways that I've done it have been:

    1) From a lisp routine, select the directory to process and using lisp code, build a script file that is called at the end of the routine.

    Example:

    (defun c:batch ()
    -pick directory to batch process
    -open a script file for "write"
    -for each drawing in the directory chosen, write the script parameters to the script file
    -close script file
    -call the script
    ) ; end routine

    2) From a lisp routine, select the directory to process but instead of building a script, have the lisp routine do the batch processing.

    Example:

    (defun c:batch ()
    -pick directory to batch process
    -for each drawing in the directory chosen, use lisp code to open and process the drawing
    ;;;the above line would be a (foreach drawing drawinglist OPEN, PROCESS, repeat)
    ) ; end routine

    Thanks.
     
    steveing, Aug 12, 2004
    #1
  2. steveing

    Jim Claypool Guest

    When processing a great number of drawings, depending on what you are doing
    with them, AutoCAD will eventually run ont of memory and the process slows
    down.

    If you are processing a small number of drawings and doing a small amount of
    processing, a script file will work just fine.
    A lisp routine won't do it by itself. You need a script to open a new
    drawing.
    However, a well thought out lisp routine to process the directory of
    drawings is the best way to go so that if you have to kill it you can start
    where you left off.
    With a script file you will have to figure out where you were and edit the
    script to restart.

    I use a lisp routine to do this with restart and skip capabilities for those
    drawings that just won't open. It writes a list of drawings to a temporary
    file that is updated with each new open. By using escape and shutting
    AutoCAD down, I can retrieve the RAM and restart where I left off.

    code, build a script file that is called at the end of the routine.
    building a script, have the lisp routine do the batch processing.
     
    Jim Claypool, Aug 13, 2004
    #2
  3. steveing

    steveing Guest

    A lisp routine won't do it by itself. You need a script to open >a new drawing.

    I have used lisp routines to batch process multiple drawings without the use of script files. In other words, a lisp file can open, process and close drawings (although I have also used script files in the past).

    Hmmm, I hadn't considered problems with memory. Is it that Autocad doesn't fully release the drawing when it is closed? I suppose that in addition to slowing down, it could cause the batch process to crash AutoCAD?

    Thanks!
     
    steveing, Aug 13, 2004
    #3
  4. I always do batch processing with SDI=1 and I can process 100's of drawings
    in a single session.

    --
    R. Robert Bell


    drawing.

    I have used lisp routines to batch process multiple drawings without the use
    of script files. In other words, a lisp file can open, process and close
    drawings (although I have also used script files in the past).

    Hmmm, I hadn't considered problems with memory. Is it that Autocad doesn't
    fully release the drawing when it is closed? I suppose that in addition to
    slowing down, it could cause the batch process to crash AutoCAD?

    Thanks!
     
    R. Robert Bell, Aug 13, 2004
    #4
  5. When processing a great number of drawings, depending on what you are doing
    It bear repeating, however, that as you said it depends on what you are
    doing. I ran a script across 200,000 files recently and there wasn't a
    noticeable difference in speed from the beginning to the end.

    --
    Darren J. Young
    CAD/CAM Systems Developer

    Cold Spring Granite Company
    202 South Third Avenue
    Cold Spring, Minnesota 56320

    Email:
    Phone: (320) 685-5045
    Fax: (320) 685-5052
     
    Darren J. Young, Aug 13, 2004
    #5
  6. steveing

    Jim Claypool Guest

    I always use SDI = 1 for batch processing.
    I have done enough processing in some batches that it will slow to a crawl
    after 100 or so.
    I have also done minor processing that does not seem to slow down at all.
    When AutoCAD closes one drawing and opens another it does not relinquish all
    of the memory.
    Eventually something has to give. AutoCAD will eventually crash if it runs
    out of swap space.
    I also have had problems in batches where some drawings won't open and need
    to be recovered.

    Start a batch with the Task Manager opened and watch the performance graphs.
     
    Jim Claypool, Aug 13, 2004
    #6
  7. steveing

    Jim Claypool Guest

    I've never been able to get a lisp routine to continue after the drawing
    opens.
    I'd like to see how it is done.

    use of script files. In other words, a lisp file can open, process and close
    drawings (although I have also used script files in the past).
    doesn't fully release the drawing when it is closed? I suppose that in
    addition to slowing down, it could cause the batch process to crash AutoCAD?
     
    Jim Claypool, Aug 13, 2004
    #7
  8. steveing

    T.Willey Guest

    Jim,

    You have to change sdi 1. Then you can use open in lisp format. I do it all the time for updating revisions on drawings.

    Tim

    These are from my toolbox. Watch for wordwrap.

    (defun ManyOrOne (many one / op1 sv1)

    (initget "C")
    (setq op1 (getkword "\n<C>urrent drawing only? or enter to continue. "))
    (if (/= op1 "C")
    (progn
    (if (> (opendocs) 1)
    (progn
    (alert "To many drawings open.
    Close all but one and run again."
    )
    (vl-exit-with-value nil)
    (princ)
    )
    (progn
    (if (/= (getvar "dbmod") 0)
    (progn
    (initget "Y N")
    (setq sv1 (getkword "\nDrawing has not be saved yet, would you like to save it [Y , <N>]? "))
    (if (= sv1 "Y")
    (command "._qsave")
    )
    )
    )
    )
    )
    )
    )
    (if op1
    (progn
    (command "_.undo" "_end")
    (command "_.undo" "_group")
    (one)
    (command "_.undo" "_end")
    )
    (progn
    (setvar "sdi" 1)
    (setvar "lispinit" 0)
    (many)
    (command "_.new" ".")
    )
    )
    )

    ;======================================

    (defun opendocs (/ opnum)
    (vl-load-com)
    (setq opnum (vla-get-count (vla-get-documents (vlax-get-acad-object))))
    )
     
    T.Willey, Aug 13, 2004
    #8
  9. steveing

    Jim Claypool Guest

    Thanks, Tim.

    You left out the two routines that do the work, one and many. Can you post
    those?

    Jim

    it all the time for updating revisions on drawings.
     
    Jim Claypool, Aug 16, 2004
    #9
  10. steveing

    T.Willey Guest

    Those are put in by what you need to do per drawing. I can post what I did in mine.

    On second thought, after looking at the code. It is better if I post the lisp routine I use, so here you go.

    Tim
    ps. Revome the ".zip" to make it a useable lisp file.
     
    T.Willey, Aug 16, 2004
    #10
  11. steveing

    dblaha Guest

    In addition to having SDI set to 1, it helps to have LISPINIT set to 0.
     
    dblaha, Aug 17, 2004
    #11
  12. steveing

    Jim Claypool Guest

    Thanks again Tim.
    After looking at the code, it seems that the one function that will give me
    what I need is (OPEN_FUN) which is not included. Can you help one more time?

    Jim

    lisp routine I use, so here you go.
     
    Jim Claypool, Aug 17, 2004
    #12
  13. steveing

    T.Willey Guest

    Here you go Jim.

    (defun DIRECTORY-DIA ( / sh folder parentfolder folderobject result)
    ;By Tony Tanzillo
    ;Modified by Tim Willey
    (vl-load-com)
    (setq sh
    (vla-getInterfaceObject
    (vlax-get-acad-object)
    "Shell.Application"
    )
    )

    (setq folder
    (vlax-invoke-method
    sh
    'BrowseForFolder
    0
    ""
    0
    )
    )
    (vlax-release-object sh)

    (if folder
    (progn
    (setq parentfolder
    (vlax-get-property folder 'ParentFolder)
    )
    (setq FolderObject
    (vlax-invoke-method
    ParentFolder
    'ParseName
    (vlax-get-property Folder 'Self)
    )
    )
    (setq result
    (vlax-get-property FolderObject 'Path)
    )
    (mapcar 'vlax-release-object
    (list folder parentfolder folderobject)
    )
    (setq result (strcat result "\\"))
    )
    )
    )

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    (defun OPEN_FUN (sub_fun / dl2 dl3 dl4 dl5 lbox1 dlng1 dlng2)

    (if (setq dl2 (DIRECTORY-DIA))
    (progn
    (setq dl3 (vl-directory-files dl2 "*.dwg"))
    (setq dl3 (vl-sort dl3 '<))
    (MULTI_SEL)
    (if (and lbox1 (/= lbox1 ""))
    (progn
    (setq lbox1 (read (strcat "(" lbox1 ")")))
    (setq dl3 (mapcar '(lambda (a) (nth a dl3)) lbox1))
    (setq dlng1 (vl-list-length dl3))
    (setq dlng2 0)
    (while (/= dlng1 dlng2)
    (progn
    (setq dl4 (nth dlng2 dl3))
    (setq dl5 (strcat dl2 dl4))
    (setq dlng2 (+ dlng2 1))
    (if (= (getvar "dbmod") 0)
    (command "open" dl5)
    (command "open" "y" dl5)
    );-if
    (SUB_FUN)
    );-progn
    );-while
    );-progn
    (exit)
    );-if
    );-progn
    (vl-exit-with-error)
    );-if

    )

    ;=================================

    (defun Multi_Sel (/ msdia1)

    (setq msdia1 (load_dialog "CloseDwg.dcl"))
    (if (not (new_dialog "Cdrawings" msdia1))
    (exit)
    );-if

    (mode_tile "d-save" 1)
    (start_list "tx2" 3); clear the list
    (mapcar 'add_list dl3)
    (end_list)

    (action_tile "accept"
    "(progn
    (setq lbox1 (get_tile \"tx2\"))
    (done_dialog 1)
    )";-progn
    );-action_tile

    (action_tile "cancel"
    "(progn
    (setq lbox1 nil)
    (done_dialog 1)
    )";-progn
    );-action_tile

    (start_dialog)

    )

    Tim
    ps. I attached my dcl just incase, again erase the ".zip" to make it a real dcl file.
     
    T.Willey, Aug 17, 2004
    #13
  14. steveing

    Jim Claypool Guest

    Thanks, Tim.

    real dcl file.
     
    Jim Claypool, Aug 17, 2004
    #14
  15. steveing

    T.Willey Guest

    Hope you can read all my garbage. If you have any questions on the code, just post and I will try and answer.

    Happy reading.
    Tim
     
    T.Willey, Aug 17, 2004
    #15
  16. steveing

    Dean McCarns Guest

    Steve;

    Why not use DBX?! Opening, closing, drawings is a beast as far as time is
    concerned. For example, when I was hired to convert 1200 drawing files
    (they wanted to go into all of there sheet files and replace a reference) I
    created a small routine that would access each file remotely (in other
    words, would not open the files GUI just the database - saves about 99% of
    the time to open a file) make the change, release the file and move on to
    the next one. Each file took an average of about 1 to 2 seconds. I ran the
    process and went on to doing another project. After less than an hour all
    of the files were converted. I had built in an error handler that would
    pre-process the function to tell if there would be a problem (or error) if
    the function was run in a drawing and if so it scipped that file (total of 2
    files), those I manualy updated.

    I'm not sure what your batch converting but I'm willing to bet my dog
    (springer) that if you built this with DBX you would save a massive amount
    of time and $$$$$$ instead of eating up all that computing memory with
    opening anc closing files. Even though you close the drawing, your still
    fragmenting your memeory every time you open the drawing and thats not to
    mention all of the time it takes to load the GUI and reload any apps defined
    in the *doc.lsp file. Turst me, if you use DBX for this type of work, you
    will smack yourself in the head with whatever heavy instrament is near by
    for ever considering anything else.

    And, if your doing this for a company (as an employee) think about how cool
    you will look when you run a function for your boss and a minute later its
    done? Can you say "CAD Ninja"? Then you can go back and say, "I just saved
    you $$$$$, lets talk bonus - which is less than the difference of what it
    would have cost if we were to have done this the traditional way".

    "....can you feel the power!!!! Oh ya! I can feel it!!!"

    --
    Dean McCarns
    ESP,Inc.
    (804) 675-2377
    code, build a script file that is called at the end of the routine.
    building a script, have the lisp routine do the batch processing.
     
    Dean McCarns, Aug 19, 2004
    #16
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.