It is possible to launch AutoCAD with ironpython and then set the application to invisible.
However, for a few seconds after launch, the user will be able to see AutoCAD's UI.
IronPython script
import clr
import System
from System import Type, Activator
print ('script running')
acApp = Activator.CreateInstance(Type.GetTypeFromProgID("AutoCAD.Application"))
acApp.Visible = 0
acApp.ActiveDocument.SendCommand("(Princ \"Hello World from Python!\")(Princ)\n")
print ('script complete')
How to run IronPython as a script
https://github.com/IronLanguages/ironpython2/releases/tag/ipy-2.7.11
If you really don't want the user to see AutoCAD, then check out AutoCAD's core console.
It's a truly headless version of AutoCAD, the UI doesn't appear at all.
Core console can run some of AutoCAD's functionality.
The main draw is the UI doesn't show up at all, so it's faster.
The paths in these files below are designed to work as follows:
- ./Bat <= coreConsoleForLoop.bat lives here
- ./Input-Files <= the dwgs to loop over live here
- ./Scripts <= the lisp scripts live here
- ./Output-Files <= any output files are sent here
The paths will need to be edited for your machine.
coreConsoleForLoop.bat
@echo off
FOR /R %%f IN (..\Input-Files\*.dwg) DO (
REM export jpg without any formatting
REM core-export-jpg-no-formatting
"C:\Program Files\Autodesk\AutoCAD 2018\accoreconsole.exe" /i "%%f" /s "C:\Users\PathTo\Scripts\core-export-jpg-no-formatting.scr" /l en-US
REM require keystroke to continue
REM useful for individual file validation during the batch process
REM useful during testing
REM :: Press any key to continue
REM timeout /t -1
)
REM 10 second pause at end of program to evaluate windows command prompt state
timeout /t 10
core-export-jpg-no-formatting.scr
;;; save drawing information
(setq drawingName(substr (getvar 'dwgname) 1 (- (strlen (getvar 'dwgname))4)))
(setq imageExtension ".jpg")
(setq imageName (strcat "..\\Output-Files\\" drawingName imageExtension))
;;; AutoCAD command line inputs
(setq objectsToPrintStringOption "ALL")
;;; zoom extents and export
ZOOM EXTENTS
REGEN
;;; enter JPGOUT command and use variables to set options
JPGOUT
;;; Enter file name:
!imageName
;;; Select objects to print or <ALL\Extents\more options...>
!objectsToPrintStringOption
;;; there must be a blank line after sending a string into the object selection argument
;;; AutoCAD command line quit with discard changes
;;; Must stay on same line to exit correctly, with this specific script, for some reason
;;; There must be a space after YES
_QUIT YES