I would like to run an AutoCAD script, print the resulting drawing to PDF and exit AutoCAD, all without a single click (so we can schedule it on a server). Is that possible with AutoCAD?
3 Answers
Yes, use the /b
command line parameter
/b Script name
Designates a script to run after you start the program (b stands for batch process). If the script file is in the Start In folder, a full path to the script file is required unless this security measure is suppressed either by including the /six command line switch, or setting the LEGACYCODESEARCH system variable to 1. Scripts can be used to set up drawing parameters in a new drawing file. An SCR file type is assumed.
If you want AutoCAD to exit after completing the script, you will need to include that as part of the script as well.

- 28,043
- 9
- 61
- 79
-
Beautiful! The only problem I have now is: AutoCAD opens Adobe Reader and leaves it open after closing itself. That means every time we run the script we'll have a new Reader instance started. Is there a way to tell AutoCAD not to open Adobe Reader? Here is my test script: https://gist.github.com/anonymous/4b4c09507da347c59fb45bacfde7cd74 – dijxtra Oct 10 '17 at 09:45
-
2Mmm, I've got a similar script for an application. I'm using AcCoreConsole from DWG TrueView instead of AutoCAD itself, but I've not seen it start Adobe Reader and it does use the same printer driver. You sure something else is not doing that, like in a batch file? Otherwise there may be some setting in AutoCAD that is trying to be "helpful". – crashmstr Oct 10 '17 at 12:29
-
Excellent, will try out AcCoreConsole as soon as I get my hands on a newer version of AutoCAD. Thanks! – dijxtra Oct 12 '17 at 11:35
I do it in ZWCAD (AutoCAD alternative) but I suppose in AutoCAD should be the same. You can create .bat file where run AutoCAD with parameter - path to script file. In script file (*.scr) You can plot to PDF or run LISP which do what You want. PrintDWG.bat:
"C:\Program Files\ZWSOFT\ZWCAD 2018\ZWCAD.exe" /b F:\PrintDWG.scr
PrintDWG.scr:
_filedia 0
_open "c:\Path\Drawing.dwg"
(load "F:\\____Zgłoszenia\\0001965\\PrintDWG.lsp")
_filedia 1
PrintDWG.lsp
(command "_-plot" "_Y" "Layout1" "PDFCreator" "A4" "_M" "I" "N" "" "" "" "N" "." "T" "" "" "N" "")

- 1,532
- 2
- 21
- 27
If you're simply scripting Autocad tasks, you should use AutoDesk's accoreconsole.exe. You can find this console app in the same folder as your acad.exe. It has (almost) all the same libraries as Autocad, but it is super light weight because there is no UI -> therefore VERY FAST. I use accoreconsole for all of my company's drawing processing needs, and it is fantastic!
This will get you started: http://adndevblog.typepad.com/autocad/2012/04/getting-started-with-accoreconsole.html
Let me know if you have any more specific questions once you've had time to look at it.

- 1,780
- 1
- 14
- 23
-
Uuuuu, this is good. I have AutoCAD 2010 which does not have accoreconsole.exe, will be getting the version with accoreconsole ASAP. Thanks! – dijxtra Oct 12 '17 at 11:34
-
I believe that if you get DWG True View, which is free from AutoDesk, it comes with accoreconsole. May save you a few bucks if you weren't planning on upgrading. You can get it here: https://autodesk-dwg-trueview.en.softonic.com/?ex=DSK-309.5 – Nik Oct 12 '17 at 14:30
-
v2013 has the best core console - they broke it soon after. see my rant at https://forums.autodesk.com/t5/net/accoreconsole-exe-in-2015-doesn-t-do-system-console-writeline/td-p/5539352 – CAD bloke Oct 26 '17 at 01:04
-
@CADbloke That's very interesting hearing you mention that. I only use accoreconsole to process massive piles of drawings silently, and I have nothing but love for it since it has been absolutely great for us. All my code is done in C#, and I never care about the console output. When I develop, I use AutoCad and the VS debugger and it works like a charm, then deploy with the console to users. That being said, there have been times in the early days where I wanted to output to the console, and was unable to. That was very annoying! Now it all makes sense. – Nik Oct 26 '17 at 02:10
-
I write my coreconsole output to a logger - Serilog' RollingFile sink. I use the async sink if there are a lot of logs. If you're into unit testing, try https://github.com/CADbloke/CADtest I'm using RealDwg for another app so that doesn't have the coreconsole issues. Yeah, not cheap. – CAD bloke Oct 26 '17 at 02:19
-
I'd be surprised the TrueView's coreconsole did anything useful. Surely half the API is missing? – CAD bloke Oct 26 '17 at 02:20
-
when you open the core console in v2018 the fisrt line points to the file in %temp% where the `stdout` is redirected to. – CAD bloke Oct 26 '17 at 02:26