Son of a Batch! AutoCAD Core Console Through Lisp

AutoLisp is a very convenient tool for making custom commands and automating tasks, but there are some trade-offs that are made when working with the convenience of the built in Visual Lisp IDE. One limitation is using Autolisp to perform functions in an MDI environment (Multiple Document Interface). This can make doing some tasks on multiple drawings very slow for large documents, or impossible depending on the task that is being performed.

Let’s say for example that you need to detach all Xref’s from a list of DWG’s. I know what you’re thinking, “Well I’ll just use scripting”. While this does work, depending on the size of the DWG, number of DWG’s and size/number of Xref’s that need to be detached, it could potentially bind up AutoCAD on your machine for quite some time.

Another solution to this would be using .NET. .NET is an efficient solution, and a very powerful tool, but in my opinion being able to use the VLIDE inside of AutoCAD is much more convenient to write something for more trivial tasks.

So what is the AutoCAD Core Console? Core Console is basically a stripped down version of AutoCAD from a User Interface perspective, while still maintaining almost all of the programs functionality. This lends itself to being useful when performing Batch Processing on large complex drawings. The .exe for core console is located in the AutoCAD install folder and is named accoreconsole.exe. If you open it up you will notice that it resembles any other console based I/O application. But don’t let the lack of ribbons and toolbars fool you. Almost all of the power and functionality of AutoCAD is still at your disposal.

It is important to note that almost all GUI (Graphic User Interface) oriented operations will not be available from Core Console. This includes the File Dialog. You may notice that if you attempt to open up a drawing using the “open” command from the console, nothing happens. As far as I am aware, you can only open drawings from using the command line switch that if fed into core console when initiating the application from AutoCAD (or another program). These command line switches are shown at the top of the screen when you first open up the core console:

/i: Specifies the drawing to run a script file on

/s: Specifies the script file to execute

/l: Specifies the language pack to run

/isolate: Used if you do not want changes to the system variables to affect all AutoCAD documents (localizes the system variable changes to the instance of Core Console)

In order to run Core Console from AutoCAD, you can simply use the “Start” command either in the command prompt, or through the “command” function in Lisp. When starting the console from AutoCAD, there is no need to provide the entire path. Below is a code snippet that illustrates how to open a drawing named “Example.dwg” and run a script named “DoWork.scr”:

Though the command line:

 

Through Lisp:

You can see how easy it would be to pass a list of full DWG paths into CoreConsole and execute a script:

Below is a short routine that can be used to experiment with running a script through core console on all of the DWG’s in a user specified file directory (Click on image to download LSP):

Note: If you do not want to run the script on all dwgs in a specific directory, or if you want to run the script on files in multiple directories, the Lee Mac “Get Files Dialog” is an excellent tool.

Since Core Console is so lightweight on performance demand (when compared to full AutoCAD), you don’t have to worry about passing several large DWG’s into the “dwgList” variable; Your operating system will manage what processing power goes where, and how many consoles open up at one time. While AutoCAD is well known to not be multi-thread safe, each instance of Core Console is, in essence, a separate instance of AutoCAD. This make it easy to utilize more of the available threads on your machine to do work.

You can use or call standard lisp functions from the scripts that are fed into core console. Unfortunately, ActiveX is not supported through the console, so if you have existing lisp routines that you want to run on a batch of drawings, they will need to be modified to work without the use of ActiveX before calling them through Core Console.

Below is a simple script that you can use to get started. Used in conjunction with the Lisp example above, it will plot all of the drawings in a user defined file path. After you become familiar with the command line switches, as well as what commands/Lisp functions can be executed through core console, it really becomes a matter of writing regular scripts (.scr files). (Click on image to download SCR):

In the attached video I am plotting 20 .dwgs. Pretty cool huh? What’s better is that if I was plotting, oh let’s say 100 .dwgs, the current instance of AutoCAD that the lisp was initiated from will be available after all of the Consoles have been started, not completed.

Hopefully this post has given enough information to allow you to start experimenting with the AutoCAD Core Console and the time saving batch possibilities that it supports. Please leave a comment below with feedback or questions. For more information, here are a few links to several excellent posts on the subject:

Through the Interface: “The AutoCAD 2013 Core Console”

Through the Interface: “Commands that ‘work’ in AutoCAD Core Console 2013”

AutoCAD Tips: “Up and Running with the 2013 Core Console”

7 thoughts on “Son of a Batch! AutoCAD Core Console Through Lisp

  1. Skylar,

    Thanks for this post i love using Autolisp and i have been looking for something to do batch operations like this.
    I think i might have some kind of configuration issue because when i test the lisp i can get accoreconsole to open
    but beyond that all i can get it to do is open a new file from Qnew template file path regardless of the arguments placed. And the arguments seem to be case sensitive, when I use lowercase /i for the file path argument core console flashes open and then closes with no effect on the specified file. When i use /I it creates a new file from Qnew. Also when i use lower case /i it generates an temp file

    Temp file called accc34642 which reads m_kernelList still has 1 entry

    I was wondering if any of this sounds familiar to you?
    I would appreciate any help you could provide on this.

    Like

    1. Wade,

      Thank you for reading the post and thank you for your reply. Without actually looking at your lisp, it sounds like there may be a problem with one of the arguments, not just the command line switches themselves. Could you post the exact statement that you using?

      Thank you,
      Skylar

      Like

      1. Skylar,

        Thanks for the quick reply
        When i the lisp i was trying the first time didnt work i started making a bunch of little changes one at a time but when i saw your reply i retried your original lisp and it worked 🙂
        But i found the problem was that the file name i was trying to access has Spaces and Underscores
        So now for the code
        (defun C:DoCore ()
        (command “start” (strcat “accoreconsole.exe ”
        “/i C:\\Users\\wwessels\\Documents\\TEST\\Test.dwg ”
        “/s C:\\Users\\wwessels\\Documents\\TEST\\Plot2PDF.scr ”
        ” /1 en-us”)))
        Works Great
        The following fails

        (defun C:DoCore ()
        (command “start” (strcat “accoreconsole.exe ”
        “/i C:\\Users\\wwessels\\Documents\\TEST\\Model_D_ARCH01_ FIRST FLOOR PLAN.dwg ”
        “/s C:\\Users\\wwessels\\Documents\\TEST\\Plot2PDF.scr ”
        ” /1 en-us”)))

        and produces an error in my temp files
        accc49402 m_kernelList still has 1 entry.

        So i guess my real question is now How do i get around the file name discrepancies and still execute scripts?
        I have heard special characters in file names is bad practice but i am working with an existing set of files and don’t have that much say in what future files are named.

        And i should probably state my near term goal for this in case you know of a better way.
        I am trying to use core console to scan directories for corrupt files i wanted to compile a list of corrupt files for I.T to Recover.
        These files won’t open or recover using any of the traditional means.

        Thanks again for the quick reply and i appreciate any help you can provide.

        Like

      2. Wade,

        Underscores should be fine, but whenever you have spaces in a file path, the entire path needs to be enclosed in quotes. If you use the following routing, It should work:

        (defun C:DoCore ()
        (command “start” (strcat “accoreconsole.exe ”
        “/i /”C:\\Users\\wwessels\\Documents\\TEST\\Model_D_ARCH01_ FIRST FLOOR PLAN.dwg/” ”
        “/s C:\\Users\\wwessels\\Documents\\TEST\\Plot2PDF.scr ”
        ”/l en-us”)))

        The only thing I did was add quotes, preceded by an escape character so that they are included in the string. You will notice in the routine from the post that works on a entire directory of files, both the file path and script are enclosed in quotes during concatenation to account for possible spaces. As far as the scanning for corrupt files goes, are you able to audit them through core console even though you are unable to open them through standard AutoCAD? Since Core Console is basically AutoCAD striped of its UI, I am guessing you might have the same issue.

        Hope this helps,
        Skylar

        Like

      3. Skylar,

        Thank you for that tip I will remember that file paths with spaces need to be enclosed in quotes for the future, i also might do some review of string manipulation in lisp.
        i tested out the Lisp that works on Directories yesterday, it works fantastically.
        As for the corruption tester i am not able to audit them through core console.
        The idea i was forming was something like using an error handling function of some kind that will write a line to an excel file if the script fails to run.
        This is if i can’t find a script that Script pro will run that will fail on the corrupt ones and pass on the good ones, right now it currently returns “Done” on files that are corrupt and Fails on files with xrefs that can’t be found.
        I will be putting a little more effort into script pro and then turning back to lisp.
        And if autolisp can’t do it i might turn to .net and see what i can do their.
        I would be very interested to hear any advice you have on this error handling function idea and if it is feasible or not.

        Thanks again for the sample lisp routines advice and quick feedback.
        This is my favorite BIM blog and i really appreciate all the work you and your co-workers put into it.

        Like

  2. Interesting solution to batch process through a directory……..i quite like it in fact…….at the moment i’m using a tool produced by the autodesk boffins – called Script Pro 2.0 which is worth looking into……i don’t think they’re maintaining it though. it affords parallel processing. but ur solution is short and sweet.

    Like

    1. Thank you Ben. I have poked around a little bit with Script Pro but not much. Alot of the tools that I use are dynamically writing the scripts to be executed so Acad Core Console comes in handy for those occasions. The SonOfABatch plugin in the post “Sonofabatch plugin: a multi-batch utility” actually starts seperate instances of Core Console for the batch plot portion of the utility.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s