View Full Version : Batch processing .lsp routine to multiple drawings
Simon G
2010-10-08, 03:28 AM
Hi all,
Hope I am not asking the obvious here, but a quick search didn't turn up results...
How do I batch run a .lsp file over a number of drawings? I used to have a .vlx program called runbatch which did the job nicely however it no longer works with AutoCAD 2011. I have only a very basic knowledge of LISP.
cheers
Simon
BlackBox
2010-10-08, 01:42 PM
You could create a script (.SCR) file.
Provided your .LSP is loaded with ACADDOC.lsp, place a command call (for your .LSP) after each drawing is opened, run your command, then save and move onto the next drawing... etc.
irneb
2010-10-08, 02:03 PM
There are various ways. The 3 "easiest" is to install one of the following proggies:
BatchLisp (http://www.jefferypsanders.com/autolisp_batchlisp.html)
ScriptPro (http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=4091678&linkID=9240618) (only on 32bit)
AutoScript (http://www.cadig.com/products/autocad-script-pro.php)The 1st is the easiest to run your LSPs on several drawings ... not the least error prone though. For the other 2 you need to write a SCR file which loads and runs your LSP. The one which works best with erroring DWGs is ADesks ScriptPro, but it only works on 32bit systems. The AutoScript works a lot similar to ScrPro, but runs directly inside ACad, I have found it to sometimes hang if the drawing's bad.
TimSpangler
2010-10-10, 03:00 PM
The absolute easiest way is to rename your Acad.lsp (acad.lsp.old) then name your new lisp acad.lsp.
Then just open the drawing that you want to process. (make sure that you comment our the defuns (they won't be necessary).
When you are finished just do the opposite.
Simon G
2010-10-11, 04:48 AM
Thanks all,
I will try AutoScript as I am running a 64-bit system. I was aware of the option to run lisp on drawing open, but wanted to open run save and close on whole directories of files.
cheers
Simon
irneb
2010-10-11, 07:32 AM
The absolute easiest way is to rename your Acad.lsp (acad.lsp.old) then name your new lisp acad.lsp.
Then just open the drawing that you want to process. (make sure that you comment our the defuns (they won't be necessary).
When you are finished just do the opposite.Only if you change the AcadLspAsDoc to 1 (which is not default, and IMO is not the best idea). In which case change the ACAD.LSP in Tim's post to ACADDOC.LSP - then you don't need to set any variables.
Of course you still need to open the DWGs manually for the "automatic" lisp to run on them. Which you can script, but then you start loosing the ease of just selecting files and / or folders to run the lisp / script on. So yes, this would be "easiest" if there's a small amount of DWGs - opening them all in one go. But if you've got hundreds, it's not as simple - then the file/folder selection tools make more sense.
There is a nice way of implementing Tim's suggestion though: You can place (say) a button on a toolbar which would rename-swap the ACADDOC.LSP files. Effectively turning the scripting on/off. But I'd only use this for a handful of DWGs at a time.
If I want to perform the same tasks on multiple DWGs, I want to set it and forget it, so I can continue with something else: another reason AutoScript is "better" than ScriptPro ... SC will open a new session of ACad for each DWG in turn, so you constantly get this ACad window popping up (effectively bugging you each time), since AS runs inside one single ACad session this doesn't happen - you can work inside another ACad session without interruption.
Simon G
2010-10-11, 11:45 PM
Ok, I have now run into another issue. AutoScript is now working as per expected, however I am not sure that it can solve my issue.
The problem I have is with a 3rd party software addon that we use. After an update in version I now get a window pop-up giving me an error each time I open a drawing created with the old version.
The plan was to clear the error (which I can do), but this doesn't seem to be possible as I can't seem to clear the dialogue box which pops up with scripts.....is this possible?
All I need the script to do is an 'enter' - or ok on the dialogue box - and then I can run the commands to clear the problem. Are scripts capable of doing this? I have tried to put a delay and a few blank lines for 'enter' but no luck.
cheers
Simon
irneb
2010-10-12, 06:39 AM
Not normal scripts no - they have no way of interacting with dialogs. If you need to send keystrokes to a dialog then you'll need some ActiveX together with VBScripting:
(vl-load-com)
;;; Send keystrokes to the current window / dialog
(defun SendKeys (keys / ws)
(if (setq ws (vlax-get-or-create-object "WScript.Shell"))
(progn
(vl-catch-all-apply (vlax-Invoke ws 'SendKeys keys))
(vlax-release-object ws)
)
)
)You'll call it in the SCR file like (SendKeys "keystrokes"), e.g. to send an Enter:
(SendKeys "~")For more info on the SendKeys method: http://msdn.microsoft.com/en-us/library/8c6yea83%28VS.85%29.aspx
BlackBox
2010-10-13, 12:52 PM
:: SIDEBAR ::
Irneb,
I'm finding "Wscript.Shell" (WS) to be potentially more useful, the more development I do.
For example, I automated my employer's Project Archival process using the expected findfile, vl-mkdir, vl-directory-files, and vl-file-copy, etc.
Now that I know about WS, I'm curious (before I go re-writing my code), do you think that WS is faster than ActiveX (obviously depending on the inherent task being performed)?
irneb
2010-10-13, 03:35 PM
I couldn't honestly tell you. I've never done a test like that. I'd think they wouldn't be much different speedwise if you don't create the object every time (i.e. try to re-use it). However, be careful when using COM objects outside of ACad - they're not released from RAM through the normal garbage collection (you have to release them manually).
BlackBox
2010-10-13, 03:54 PM
I couldn't honestly tell you. I've never done a test like that. I'd think they wouldn't be much different speedwise if you don't create the object every time (i.e. try to re-use it).
No worries. Sounds like a fun challenge, I'll write it up, and test them against each other using a bench routine. ;)
However, be careful when using COM objects outside of ACad - they're not released from RAM through the normal garbage collection (you have to release them manually).
Tell me about it, I'm having major problems with the Land ActiveX API, where they neglected to provide a means to 'close' a surface once it has been opened (i.e., there's no close method). Releasing the surface object does nothing, even after a single, forced garbage collection. :(
But this is now way off topic... sorry for hijacking the thread.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.