TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: TimSpangler on February 29, 2012, 12:39:00 PM

Title: Batch Processing.
Post by: TimSpangler on February 29, 2012, 12:39:00 PM
What, How, do you do it?

VBA, .NET, .lsp?

Pros/Cons?

Thanks
Title: Re: Batch Processing.
Post by: danallen on February 29, 2012, 12:56:52 PM
Just started using http://www.ezscriptpro.com (http://www.ezscriptpro.com) and it worked pretty well.
Title: Re: Batch Processing.
Post by: GILESP on February 29, 2012, 01:09:04 PM
I've written a VBA script that does some fairly basic batch processing, it's slow as it has to open each file in turn, and you're at the mercy of the payload once you've opened the file, but it does the trick 9/10 times.

It's nice as I can modify the code to my needs, and write quick 'bodges' as and when someone want to move text by 5mm on 100 drawings.

Code fragment here:

Code: [Select]
    For i = 0 To Me.FilesToOpList.ListCount - 1
        Set SubDwg = Application.Documents.Open(Me.FilesToOpList.List(i, 1), False)
        DwgChanged = False
        'do stuff here

        If BatchLaunchWin.SearchChkBox Then
            DwgChanged = ChangeText(SubDwg, BatchLaunchWin.SearchTextBox.Value, BatchLaunchWin.ReplaceTextBox.Value)
        End If

The payload are functions that return true when they sucessfully execute
Title: Re: Batch Processing.
Post by: dgorsman on February 29, 2012, 01:45:41 PM
Don't do much batch work, so I custom build where needed.  When I have LSP functions that may be batched I put some consideration as to whats needed to make it work with ObjectDBX e.g. passing a database as an additional argument, with nil selecting the active drawing.  Otherwise, I use dotNET to iterate over the drawings.  Embedded calls to (command...) in some of our client-supplied FAS files results in some COM bodgy-ness so the SendStringToExecute will function appropriately.
Title: Re: Batch Processing.
Post by: Lee Mac on February 29, 2012, 01:46:53 PM
I would use this (http://www.theswamp.org/index.php?topic=31827.0) where I could, otherwise I would use a LISP to write Script that calls a LISP  8-)
Title: Re: Batch Processing.
Post by: Matt__W on February 29, 2012, 01:51:27 PM
I would use this (http://www.theswamp.org/index.php?topic=31827.0) where I could, otherwise I would use a LISP to write Script that calls a LISP  8-)
I would use a LISP to write a script that calls a VBA app that calls a LISP that opens multiple sessions of AutoCAD (in the cloud) that would then process using ODBX via OpenDCL.   All on LINUX!  Bazinga!



Well, alright..... maybe not.
Title: Re: Batch Processing.
Post by: Lee Mac on February 29, 2012, 01:53:58 PM
I would use this (http://www.theswamp.org/index.php?topic=31827.0) where I could, otherwise I would use a LISP to write Script that calls a LISP  8-)
I would use a LISP to write a script that calls a VBA app that calls a LISP that opens multiple sessions of AutoCAD (in the cloud) that would then process using ODBX via OpenDCL.   All on LINUX!  Bazinga!

:lol:
Title: Re: Batch Processing.
Post by: alanjt on February 29, 2012, 04:37:40 PM
I would use this (http://www.theswamp.org/index.php?topic=31827.0) where I could, otherwise I would use a LISP to write Script that calls a LISP  8-)
I would use a LISP to write a script that calls a VBA app that calls a LISP that opens multiple sessions of AutoCAD (in the cloud) that would then process using ODBX via OpenDCL.   All on LINUX!  Bazinga!



Well, alright..... maybe not.
mindblown.jpg
Title: Re: Batch Processing.
Post by: GDF on February 29, 2012, 04:59:11 PM
I would use this (http://www.theswamp.org/index.php?topic=31827.0) where I could, otherwise I would use a LISP to write Script that calls a LISP  8-)
I would use a LISP to write a script that calls a VBA app that calls a LISP that opens multiple sessions of AutoCAD (in the cloud) that would then process using ODBX via OpenDCL.   All on LINUX!  Bazinga!



Well, alright..... maybe not.


WTF
 :lmao:
Title: Re: Batch Processing.
Post by: dgorsman on February 29, 2012, 05:34:43 PM
I would use this (http://www.theswamp.org/index.php?topic=31827.0) where I could, otherwise I would use a LISP to write Script that calls a LISP  8-)
I would use a LISP to write a script that calls a VBA app that calls a LISP that opens multiple sessions of AutoCAD (in the cloud) that would then process using ODBX via OpenDCL.   All on LINUX!  Bazinga!



Well, alright..... maybe not.

You missed XML.   :lol:  I'll assume thats what the scripting is written with, then uses XSL and javascript/ECMA to transform it to an AutoCAD command script.
Title: Re: Batch Processing.
Post by: Keith™ on February 29, 2012, 09:21:55 PM
I have a batch plotting setup that I use.

VBA calls script that processes all the files.
Title: Re: Batch Processing.
Post by: TimSpangler on March 01, 2012, 07:43:25 AM
With the batch processor that everyone uses, are you limited to files in a single directory at a time or can you run multiple files from different locations?

Is there ever a need to run a lisp or such once the batch process has finished?

Anyone using straight lisp for batch processing?
Title: Re: Batch Processing.
Post by: GILESP on March 01, 2012, 08:12:54 AM
In theory my vba will accept files from every location, as it passes the long filename (Including path) to the open command.  I can't say I've tested that aspect yet as I've not had cause to process massed folders of drawings.

I think the context would determine if an other custom commands are required after running the batch, I've not needed anything like that so far.

I saw a piece of lisp only code once, but it relied on a windows script to open the next file, and then execute another lisp script within it, looked kinda clunky.
Title: Re: Batch Processing.
Post by: dgorsman on March 01, 2012, 10:22:25 AM
For the one major batch process I have set up, the user creates a master folder, with the drawings split up into sub-folders under that one.  Each sub-folder prompts for process yes/no? in the cycle so the user can skip that group if necessary, since some of the groups need to be processed multiple times.  It does run a pre- and post-LISP to set/remove a semaphore file in the users ACADTEMP folder; that file is used to signal the system to skip some of the standard functions which run on drawing open.
Title: Re: Batch Processing.
Post by: irneb on March 05, 2012, 03:34:49 AM
I think the best idea for a Lisp-only batch is Kean's over here: http://through-the-interface.typepad.com/through_the_interface/2009/06/index.html

The reason I say it's the "best" is it attempts to break the scripting into one script per DWG. Thus if something fails in one DWG the entire batch job doesn't fail. Though Kean's example is just that, an example. It's not showing much in the form of UI and selecting DWGs, etc. Also I'd use some other way to store the list of drawings, e.g. instead of a temp file, just use vl-propagate or vl-bb-*.

At the moment though I like AutoScript - does the job reasonably well and faster than ScriptPro. Haven't tried EzScript yet. As for VBA ... if I go that route, I might as well do the whole thing in C#.  ::) ... Which is probably just going to be a clone of AutoScript in any case.
Title: Re: Batch Processing.
Post by: deegeecees on March 05, 2012, 12:10:27 PM
I have a Lisp batch processor floating around here somewhere. It takes all dwg's from ONE directory only though. Maybe someone could expand on it. I would but I've been away from Lisp/programming for quite a while now.

Here it is:

http://www.theswamp.org/index.php?topic=21412.msg259520#msg259520
Title: Re: Batch Processing.
Post by: TimSpangler on March 05, 2012, 03:13:26 PM
The reason I am inquiring is, I have been working on one that is lisp only (no scr)  I have it to a point that it works pretty well.  Once I finish some of the documentation I will post it for everyone to tear to shreds.  It allows drawings from any location, and also has the ability to run a clean up function upon completion. (lsp, bat, exe, vbs).  I am cleaning up the code a bit and finishing up the documentation and I'll post it.
Title: Re: Batch Processing.
Post by: deegeecees on March 05, 2012, 10:53:45 PM
Sounds pretty cool, looking forward to it.
Title: Re: Batch Processing.
Post by: Rod on March 06, 2012, 12:05:22 AM
I would suggest you try scriptpro2 free download from http://labs.autodesk.com/utilities/ADN_plugins/catalog/
this is already very fast, has a good user interface and lets you know if the script was successful. This will be even faster once you have 2013 as mentioned in http://through-the-interface.typepad.com/through_the_interface/2012/02/the-autocad-2013-core-console.html
Regards Rod
Title: Re: Batch Processing.
Post by: Kerry on March 06, 2012, 02:08:08 AM

I have to agree about ScriptPRO2. I've written several batch processors over the years but I currently use scriptPRO  for all batch processing we need.  It's written in C# and works in 32 and 64 bit environments. It's well behaved and easy to use.

Regards,
 
Title: Re: Batch Processing.
Post by: irneb on March 07, 2012, 07:14:06 AM
I don't know ... I've tried ScriptPro 2 several times now, but it only works on 32bit systems (and XP at that). I've tried everything I could think of, including starting it as Administrator, changing all the settings in W7 to allow all access to every file/folder without constantly poping up with that admin access dialog, changing username to be a full admin, only working with SCR & DWG files saved direct to a user-created folder on my C drive. Etc. etc. etc.

On 32bit XP it has no benefit over the old ScriptPro (i.e. it opens an acad session for each DWG in turn). On Win7 64bit I keep getting a situation of "Can't start the acad.exe process. Only in one case did it open the ACad logo screen, and then simply close it down without doing anything.

And I can't understand what you guys mean by: "It's fast". It needs to close and restart acad for every DWG you've added to the list. AutoScript doesn't need to do that since it runs inside of acad already - no need to start a new process, just open DWG, run SCR, close DWG ... next.

Anyhow, the very oldest LSP only thing I could find is this: http://www.jefferypsanders.com/autolisp_batchlisp.html
But that one sets SDI=1 in order to force acad to only have one DWG open at a time - i.e. it then works like the very old (early 90's) acads.
Title: Re: Batch Processing.
Post by: Kerry on March 07, 2012, 02:51:13 PM
I don't know ... I've tried ScriptPro 2 several times now, but it only works on 32bit systems (and XP at that). I've tried everything I could think of, < .. >

I run it on a group of 64 bit machines with impunity.

... and yes, speed is relative ... it's not as speedy as some of my old lisp controllers ... but it behaves well if a drawing errors out.
Title: Re: Batch Processing.
Post by: CADDOG on July 27, 2012, 01:03:35 PM
I would seriously revisit Lee Macs post about his ODBX wrapper.  He's really under selling it.  One of the best implemenations of ODBX near plugin capability.

See how fast DBX can opperate - see below.

Combine your function with his LM:GetFiles function and that will prep a list formatted for his LM:ODBX wrapper function.  (LM:GetFiles btw is the best file selectors I've seen.)


Without the additional called functions, here's another example of using his wrapper.

First here, we get options from the user
Code: [Select]
(initget "Valves Linenumber Equipment Instrument")
  (if (setq opt (getkword "\nChoose Extraction Type [Valves/Linenumber/Equipment/Instrument] <exit>: "))
    (if (findfile (strcat "advanExtract_" opt ".lsp"))
      (load (strcat "advanExtract_" opt ".lsp"))
      (princ (strcat "Missing: BorderExtract" opt ".lsp")))
    ;not opt then exit
    (exit)
    )
 
  (initget "Select Current")
  (setq opt (getkword (strcat advan_Outfile ":  " "Process [Select files/Current dwg] <Current dwg>: ")))
  (cond
    ((= opt "Select")
     (cond
       ((not LM:ODBX) (princ "DBX Wrapper function not loaded.  See Admin"))
       ((not LM:GetFiles) (princ "Get Files Wrapper function not loaded.  See Admin"))
       ((not advan_Outfile)) ;we've already warned, just making sure these got set
       ((not advan_BlockList)) ;public var loaded by (load (strcat "advanExtract_" opt ".lsp"))
       ((not advan_TagList)) ;public var loaded by (load (strcat "advanExtract_" opt ".lsp"))
       (t (_extraction t)))
     )
    (t
     (_extraction nil)
     )
    );cond

And then there's the actuall implementation of his ODBX wrapper and GetFiles function
Code: [Select]
  (defun _extraction (runfolder / doc dwgname data name file item a)
    (setq name "")
    (setq doc (vla-get-activedocument (vlax-get-acad-object))
  dwgname (vla-get-fullname doc))
    (cond ((and (not runfolder)
(setq name (strcat (vl-filename-directory dwgname) "\\" (vl-filename-base dwgname) " " advan_Outfile))
(setq data (_parseattributes (list (append (list dwgname) (_getattributes doc)))))
);and
   (setq name (_getsavefile "Choose Extract Save File" name "CSV"))
   )
  ((and (setq name (strcat (vl-filename-directory dwgname) "\\"))
(setq runfolder (LM:GetFiles "Select Files to Process" name "dwg"))
(setq data (_parseattributes (LM:ODBX '_getattributes runfolder nil)))
(setq name (strcat (vl-filename-directory (caar data)) "\\" advan_Outfile))
(setq name (_getsavefile "Choose Extract Save File" name "CSV"))
);and
   )
  );cond
...
...
...

The rest of the code is just parsing the return data to a deliminated out file.
Notice my call to his _getattributes function.


Another implementation translated 3384 attributes on 130 drawings in 14.25 seconds.
Code: [Select]
     Processing Results
---------------------------
     Drawings Processed: 130
  Translated Attributes: 3384
        Processing Time: 14.25 seconds

I can't say enough about DBX and how Lee has brought, the more confusing implementation of it, down to my level.

NOTE:  Don't forget that you can vl-propagate a var if you need to supply more info to your function derived by user interaction at the beginning.
Title: Re: Batch Processing.
Post by: Lee Mac on July 28, 2012, 03:17:06 PM
Wow! -  Many thanks for your high praise for my functions CADDOG, I very much appreciate it. That's fantastic to hear that you are able to utilise the functions in your programs, and it's great that you are also pleased with the results  :-)

ObjectDBX is indeed a powerful tool when used in the right way, and I'm pleased that my ObjectDBX Wrapper has made the interface more accessible for other developers to use in their programs.