I can't give you a full on working solution, but I think I can give you enough code and steps to get you moving in a direction. First off, your going to need an AutoCAD plugin that will open a file, find a layout, and print that layout using the plot settings and media settings for that particular layout (or provide settings and media to plot against). There are probably several out there that you can use, we wrote our own because we have our own settings and media. Here is some code to sort of show you a way to do it - its the two methods that do most of the heavy lifting as far as printing. You can use this as a basis to write your own DLL that can be loaded as a plugin:
/// <summary>
/// Generates views from a drawing document.
/// </summary>
/// <param name="tbl">The Titleblocklayout (our target).</param>
/// <param name="sizeStandard">The size standard - ANSI or our custom.</param>
/// <param name="outputDevice">The device/driver to plot to</param>
/// <returns>True is successful, false otherwise.</returns>
public bool GeneratePlotfilefromDocument(TitleBlockLayout tbl, string sizeStandard, string outputDevice, string layoutName)
{
string filename = string.Empty;
string extension = ".cal";
if (outputDevice.Equals(DWF_DEVICE))
extension = ".dwf";
else if (outputDevice.Equals(HPGL_DEVICE))
extension = ".hpg";
bool isMultiSheet = false;
var doc = ThisCommandClass.GetDocumentByName(tbl.DrawingPath);
if (null == doc) return false;
if (ACADApp.Application.DocumentManager.MdiActiveDocument != doc)
ACADApp.Application.DocumentManager.MdiActiveDocument = doc;
object bgPlot = ACADApp.Application.GetSystemVariable("BackGroundPlot");
ACADApp.Application.SetSystemVariable("BackGroundPlot", 0);
object trasparencyPlot = ACADApp.Application.GetSystemVariable("PLOTTRANSPARENCYOVERRIDE");
ACADApp.Application.SetSystemVariable("PLOTTRANSPARENCYOVERRIDE", 0);
Layout targetLayout = null;
using (ACADApp.DocumentLock dl = ACADApp.Application.DocumentManager.MdiActiveDocument.LockDocument())
{
using (Transaction tr = ACADApp.Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction())
{
var layoutDic = tr.GetObject(ACADApp.Application.DocumentManager.MdiActiveDocument.Database.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;
if (layoutDic == null) return false;
isMultiSheet = (layoutDic.Count >= 2);
foreach (var layoutRef in layoutDic)
{
var layout = layoutRef.Value.GetObject(OpenMode.ForRead) as Layout;
if (null == layout) continue;
var btr = layout.BlockTableRecordId.GetObject(OpenMode.ForRead) as BlockTableRecord;
if (null == btr) continue;
if (layout.LayoutName.Equals(layoutName))
{
targetLayout = layout;
LayoutManager.Current.CurrentLayout = targetLayout.LayoutName;
break;
}
}
if (null == targetLayout)
return false;
//Create a publish engine and then send the plot through
PlotEngine pltEng = PlotFactory.CreatePublishEngine();
try
{
LayoutManager layoutMgr = LayoutManager.Current;
ObjectId layoutId = layoutMgr.GetLayoutId(layoutMgr.CurrentLayout);
PlotSettings pltSettings = new PlotSettings(targetLayout.ModelType);
pltSettings.CopyFrom(targetLayout);
pltSettings.PrintLineweights = true;
PlotSettingsValidator psv = PlotSettingsValidator.Current;
string pltdevice = outputDevice; //userConfigSettings.CALPLOTTERCONFIG;
string media = customConfigMedia(tbl.Size, pltdevice, sizeStandard);
if (string.IsNullOrEmpty(media))
{
MessageBox.Show("Plot files not found, please contact Tech Support.");
return false;
}
psv.SetPlotType(pltSettings, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
psv.SetUseStandardScale(pltSettings, true);
psv.SetStdScaleType(pltSettings, StdScaleType.StdScale1To1);
psv.SetPlotCentered(pltSettings, true);
//need the get before the set to avoid error
psv.GetPlotStyleSheetList();
if (outputDevice.Equals(CAL_DEVICE))
psv.SetCurrentStyleSheet(pltSettings, "monochrome.ctb");
else
psv.SetCurrentStyleSheet(pltSettings, "acad.ctb");
psv.SetPlotConfigurationName(pltSettings, pltdevice, media);
psv.SetPlotRotation(pltSettings, PlotRotation.Degrees000);
psv.SetPlotPaperUnits(pltSettings, PlotPaperUnit.Inches);
pltEng.BeginPlot(null, null);
PlotInfo pltInfo = new PlotInfo();
pltInfo.Layout = targetLayout.ObjectId;
pltInfo.OverrideSettings = pltSettings;
PlotInfoValidator validator = new PlotInfoValidator();
validator.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
validator.Validate(pltInfo);
filename = Path.Combine(Path.GetDirectoryName(tbl.DrawingPath), targetLayout.LayoutName + extension);
pltEng.BeginDocument(pltInfo, ACADApp.Application.DocumentManager.MdiActiveDocument.Name, null, 1, true, filename);
PlotPageInfo pageInfo = new PlotPageInfo();
pltEng.BeginPage(pageInfo, pltInfo, true, null);
pltEng.BeginGenerateGraphics(null);
pltEng.EndGenerateGraphics(null);
pltEng.EndPage(null);
pltEng.EndDocument(null);
pltEng.EndPlot(null);
}
catch (System.Exception es)
{
return false;
}
finally
{
pltEng.Destroy();
tr.Commit();
}
}
ACADApp.Application.SetSystemVariable("BackGroundPlot", bgPlot);
ACADApp.Application.SetSystemVariable("PLOTTRANSPARENCYOVERRIDE", trasparencyPlot);
return true;
}
/// Retrieves the correct driver from the AutoCAD driver information configuration
/// </summary>
/// <param name="size">The size of the drawing we are plotting.</param>
/// <param name="device">The device/driver name.</param>
/// <param name="standard">The size standard - either ANSI or our custom</param>
/// <returns>The name of the driver media device we are looking for.</returns>
private string customConfigMedia(string size, string device, string standard)
{
string mediaSize = string.Empty;
string target = string.Empty;
foreach (PlotConfigInfo inf in PlotConfigManager.Devices)
{
if (inf.DeviceName.ToUpper().Equals( device.ToUpper() ) )
{
PlotConfig pc = PlotConfigManager.SetCurrentConfig(inf.DeviceName);
//our custom target PC3/PMP files have sizes in them that are named this way
target = string.Format("TRANSMISSION {0} {1}", standard, size).ToUpper();
foreach (string media in pc.CanonicalMediaNames)
{
if (pc.GetLocalMediaName(media).ToUpper().Equals(target))
{
mediaSize = media;
break;
}
}
}
}
return mediaSize;
}
Now, lets assume you have a DLL that is called "MY_PRINTER.dll" and it has a method in there called "PlotLayouts() that gets a layout from the drawing and feeds it into the method above (our drawing layouts are wrapped in an object called TitleBlockLayout but it's essentially an AutoCAD layout object). Your gonna want to basically tell ACCORECONSOLE (which is AutoCAD) to load the drawing and call your method to generate the views. You can do that with an SCR (script) file called "print_my_files.scr" like this:
FILEDIA
0
NETLOAD C:\<whatever the path to your MY_PRINTER.dll library>\MY_PRINTER.dll
PlotLayouts
FILEDIA
1
From there, you can use a command prompt, batch file, whatever to call ACCORECONSOLE and netload that DLL into it with the script and do your work:
C:\Program Files\Autodesk\AutoCAD 2019>accoreconsole.exe /i "C:\blee\blah\drawingtoprint.dwg" /s "C:\blah\blee\print_my_files.scr"
Simple 72 step process 