Author Topic: BatchWORX  (Read 7508 times)

0 Members and 1 Guest are viewing this topic.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
BatchWORX
« on: April 20, 2012, 02:57:40 PM »
As promised, here is a Batch Processing utility that I have been working on for a while (several failed attempts).  I have included some documentation to help explain a little bit about how to set it up and how it works.  This is a LISP only processor, it does not rely on scripts or lisp that create scripts, etc.  It utilizes the registry along with some code in the Batchworx.lsp to run when loaded.  I have been using this for about 6 months and it has held up nicely to my testing.  I would now like to get others to test it to exspose the bugs.  I have read just about everything there is to read online about batch processing, alot of what I tried was cumbersome or hard to follow or just plain complicated.  I wanted something that was easy to implement and easy to use.

The Batchworx adds a "load" line to the Acaddoc.lsp file to load the Batchworx.lsp for each dwg.

Code inside the Batchworx.lsp checks for certian parameters when loaded.  If those parameters are met, it then loads/ executes the selected process. If the parameters are not met, the drawing loads normally. (this is checked with every dwg that is opened, this is what allows for the batch processing).

When Batchworx is executed is sets a flag in the registry to T (this turns on Batch Processing. This is one parameter that is checked)
The user will then select a batch process to run (this parameter is set in the registry so that every dwg opened now knows what process to run)
The user then selects the dwg's to process. (they can be  in multiple directories/ locations).
This list of drawings are then opened. As each drawing is opened the parameters tell the drawing which process to load.  That process is loaded and executed. The process then closes the drawing and the next one is opened, etc.
Once the last drawing is opened Batchworx opens its own dwg (Batchworx.dwg it is an empty dwg). This drawing is a trigger to turn off the Batch process and clear the parameters from the registry.

Batchworx also has the ability to run a seperate process once the batch has ended.  This can be used to create a log and open it once completed, it can be used to reset varaibles, map network drives, etc (anything you need it to do).  This cleanup process can be a .vbs, .lsp, .bat, .exe. This can be expaned to include just about anything.  There is more of an explianation in the documentation.

I have included a sample batch file that creates a log file and opens that log upon completion.

I welcome any positive feedback.  The code is still abit "dirty" so keep that in mind.  If anyone has any question feel free to ask.


*NOTICE*
Batchworx adds a line to the acaddoc.lsp as well a creating some registry entries under "HKEY_CURRENT_USER\\Software\\BatchWORX"


[EDIT]  Replaced the attachment with current files.
« Last Edit: May 30, 2012, 07:49:52 AM by TimSpangler »
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright 2016

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: BatchWORX
« Reply #1 on: April 21, 2012, 09:04:54 AM »
Great work! I was thinking along the same lines, just didn't have the time. BTW, my idea was to save a list of drawings to be opened into a registry folder. The loader would then check if the current DWG is one of them in that folder, if so - then run the script/lsp/etc. and delete that value out of the folder, then close the DWG and open the 1st one in the reg folder.

Was there a reason you didn't go that route and rather used a marker Batchworx.DWG file?
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: BatchWORX
« Reply #2 on: April 21, 2012, 07:00:15 PM »
Great work! I was thinking along the same lines, just didn't have the time. BTW, my idea was to save a list of drawings to be opened into a registry folder. The loader would then check if the current DWG is one of them in that folder, if so - then run the script/lsp/etc. and delete that value out of the folder, then close the DWG and open the 1st one in the reg folder.

Was there a reason you didn't go that route and rather used a marker Batchworx.DWG file?

One of my failed attempts was saving the list to the registry.  That could potentially be a large list and I ran into trouble with that approach.  The batch sometimes stopped for no reason.  I think the better option would be to hold the number of dwg's, then as each dwg was processed -1 that number until it was 0.  That is one thing I am getting ready to test.

Did everything work as it was supposed to?  Is there anything that could make it more user friendly?
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright 2016

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: BatchWORX
« Reply #3 on: April 24, 2012, 07:15:39 PM »
I tried using a counter set in the registry.  It worked for counting but once it was finished the process ended without cleaning up.

After looking at what is happening I realized that the batch closes the last drawing before anything can happen.  I tried changing some things around but I was unable to get it to work.  I believe that if I create a reactor in the first drawing (the calling session) and have that reactor check for that drawing to become active then check the counter I may be able to get it to work without the Batchworx.dwg.  Currently the Batchworx.dwg is the trigger that runs the cleanup then closes.

Not really sure that anyone is following this but if I get something to work I will post it here.
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright 2016

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: BatchWORX
« Reply #4 on: May 01, 2012, 08:37:35 AM »
Has anyone had any issues/ comments. I am working on this a bit more and am open to comments to make it easier to use, etc.

Thanks
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright 2016

matthewj

  • Newt
  • Posts: 42
  • Vanilla
Re: BatchWORX
« Reply #5 on: May 07, 2012, 10:32:30 PM »
Just a thought, could you put the countdown variable into the blackboard namespace?

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: BatchWORX
« Reply #6 on: May 08, 2012, 07:37:19 AM »
Just a thought, could you put the countdown variable into the blackboard namespace?

It is not the countdown that is the problem as much as it is the execution of cleanup code after the fact.  Once the drawings have been processed you are returned to the original drawing that launched the Batchworx program.  It has already done its job.  I need a way to now tell the launching drawing that the process has completed and now it is time to execute some cleanup code.  This is the reason for the Batchworx.dwg.  It is used to launch cleanup code.  It is possible with a reactor but I am trying to stay clear of reactor is I can as that would add a level of complexity to the code.  I also do not want to launch cleanup code on a .dwg that is being processed.  I don't want to risk an error during the cleanup and have that effect a dwg that is being batched.

I do believe that a reactor is going to be the best solution. (lips only).
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright 2016

matthewj

  • Newt
  • Posts: 42
  • Vanilla
Re: BatchWORX
« Reply #7 on: May 08, 2012, 08:12:49 AM »
Sorry, it was late, and I wasn't as clear as I could have been.  A reactor is where I was going with that.  I'm not familiar with your code, but this is how I saw it in my head:  When each batchworx drawing is done processing, it decrements the counter in the blackboard. When the counter reaches one, a reactor that checks the counter each time the active drawing is switched fires off the cleanup function and deletes the blackboard variable.

There is a little bit of overhead, but its not much, and writing the reactor code would be a drop in the bucket -- something like this?  (untested)
Code: [Select]
(vlr-docmanager-reactor nil '((:vlr-documentBecameCurrent . batchworx_check_counter)))

(defun batchworx_check_counter( / )
    (if (= (vl-bb-ref 'batch_counter) 1) (progn (batchworx_cleanup)(vl-bb-set 'batch_counter nil))

)

PS, I really liked the routine, it was helpful when I was populating my 3d fastener library.  So thanks for that.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: BatchWORX
« Reply #8 on: May 08, 2012, 08:21:37 AM »
That's what I was thinking, but I am using the reg to store the counter instead of the BB. Still using the document reactor.

I haven't had much a chance this week to work on it but I hope to get back to it later in the week.

How did it work?  Was the program flow good? Was it intuitive?  Any issues with how it preformed?
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright 2016

matthewj

  • Newt
  • Posts: 42
  • Vanilla
Re: BatchWORX
« Reply #9 on: May 08, 2012, 09:24:27 AM »
It worked really well.  The resulting files were great.

I did run into one issue, after processing about 10 - 20 drawings multiple sessions of autocad would start opening.  The other sessions would open about 3 to 7 drawings each.  I've posted the .batch routine I used.  I'm not sure if it was because I didn't uncomment the clean up program section...  that was a bit unclear in the documentation.

Code: [Select]
;; Add the start up
(defun S::STARTUP (/)

;;; ------------ ECHO TO THE COMMAND LINE
(princ "\n Begining Batch Process \n")

;; <LOAD DEPENDENT LISPS HERE>

;; <ADD CONTENT HERE>
(vl-cmdf "union" "all" "")
(vl-cmdf "-view" "o" "front")
(vl-cmdf "zoom" "extents")
(vl-cmdf "zoom" "scale" "0.9x")

;; Save the file - if needed
(vl-cmdf "QSAVE")

;; Set the clean up program (remove semi-colons)
;;(if  (= (vl-registry-read BatchMasterKey "Clean") "nil")
;; (vl-registry-write BatchMasterKey "Clean" "<FILENAME>")
;;)

;; Close the drawing
(vl-cmdf "CLOSE")
)s

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: BatchWORX
« Reply #10 on: May 08, 2012, 09:27:16 AM »
It worked really well.  The resulting files were great.

What version of AutoCAD?
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright 2016

matthewj

  • Newt
  • Posts: 42
  • Vanilla
Re: BatchWORX
« Reply #11 on: May 08, 2012, 10:48:01 AM »
2012 Mechanical, run as vanilla though.

I recreated what I was doing, batch processing 100 files in one directory.

When the batch process was running, I went about trying to do other stuff on my computer while the processing was going on.  I found very quickly that wouldn't work.  I also found that Autocad spawned about 28 more instances, each with 1 file open.  These 28 files were not processed.

I re-ran the batch process while doing nothing else on my computer (2 times), this time only one extra autocad process was spawned, and it opened 8 (9 in the third test) of the files.  Those eight files were not processed.



TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: BatchWORX
« Reply #12 on: May 08, 2012, 10:52:20 AM »
I think I have a fix for that.  I will post it if you want to try it?
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright 2016

matthewj

  • Newt
  • Posts: 42
  • Vanilla
Re: BatchWORX
« Reply #13 on: May 08, 2012, 11:00:44 AM »
Absolutely, this has been the easiest to use batch solution I've seen so far.  Easy enough for my non-lispy co-workers to use.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: BatchWORX
« Reply #14 on: May 08, 2012, 11:32:20 AM »
Try this one and see if this prevents multiple sessions.
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright 2016