A simple Program to Plot ModelSpace Area's would look like this:
[CommandMethod("MP")]
public static void MultiPlot()
{
Document doc = null;
Database db = null;
Editor ed = null;
string plotAreaLayerName="PLOTAREA";
string printerName = "DWG To PDF.pc3";
string plotPaperName = "ISO A3 (420.00 x 297.00 MM)";
string plotStyleName = "acad.ctb";
try
{
doc = AcadApp.DocumentManager.MdiActiveDocument;
if (doc == null)
throw new System.Exception("No MdiActiveDocument");
db = doc.Database;
ed = doc.Editor;
//1. Calculate each ModelSpace PlotArea's based on Rectangle on Layer PlotArea
var plotAreas=new List<Point3d[]>();
using (Transaction tr=db.TransactionManager.StartTransaction())
{
var lt=tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
if (!lt.Has(plotAreaLayerName))
throw new System.Exception("Layer not found: " + plotAreaLayerName);
var plotAreaLayerId=lt[plotAreaLayerName];
var ms = tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId id in ms)
{
if (id.ObjectClass.DxfName == "POLYLINE")
{
var pl = tr.GetObject(id, OpenMode.ForRead) as Polyline;
if (pl.LayerId == plotAreaLayerId)
{
//Assume no rotated areas: PlotArea==BoundingBox
var plotArea = new Point3d[2];
plotArea[1] = pl.Bounds.Value.MinPoint;
plotArea[2] = pl.Bounds.Value.MaxPoint;
plotAreas.Add(plotArea);
}
}
}
tr.Commit();
}
//2. Plot each ModelSpace Area
// Detailed plot configuration? [Yes/No] <No>: yes
// Enter a layout name or [?] <Model>: Model
// Enter an output device name or [?] <None>: dwg to pdf
// Enter paper size or [?] <ANSI A (11.00 x 8.50 Inches)>: ISO A3 (420.00 x 297.00 MM)
// Enter paper units [Inches/Millimeters] <Millimeters>: Millimeters
// Enter drawing orientation [Portrait/Landscape] <Landscape>: Landscape
// Plot upside down? [Yes/No] <No>: No
// Enter plot area [Display/Extents/Limits/View/Window] <Display>: Window
// Enter lower left corner of window <0.000000,0.000000>: PlotArea[0]
// Enter upper right corner of window <0.000000,0.000000>: PlotArea[1]
// Enter plot scale (Plotted Millimeters=Drawing Units) or [Fit] <Fit>: Fit
// Enter plot offset (x,y) or [Center] <17.34,4.14>: Center
// Plot with plot styles? [Yes/No] <Yes>: Yes
// Enter plot style table name or [?] (enter . for none) <>: acad.ctb
// Plot with lineweights? [Yes/No] <Yes>: Yes
// Enter shade plot setting [As displayed/legacy Wireframe/legacy Hidden/Visual styles/Rendered] <As displayed>: As displayed
// Enter file name <C:\temp\DwgName-Model.pdf>: c:/temp/dwgName-Scheme-1.dwg
// Save changes to page setup [Yes/No]? <N> No
// Proceed with plot [Yes/No] <Y>: Yes
var docPath=Path.GetDirectoryName(doc.Name);
if (!doc.IsNamedDrawing)
docPath=Path.GetTempPath();
var docName=Path.GetFileNameWithoutExtension(doc.Name);
Application.SetSystemVariable("FILEDIA",0);
int pltNr=1;
foreach (var plotArea in plotAreas)
{
var plotPathname = Path.Combine(docPath, docName + "-Scheme_" + pltNr.ToString() + ".pdf");
while (File.Exists(plotPathname))
{
pltNr++;
plotPathname = Path.Combine(docPath, docName + "-Scheme_" + pltNr.ToString() + ".pdf");
}
ed.Command("-PLOT", "Yes", "Model", printerName, plotPaperName, "Millimeters", "Landscape", "No", "Window", plotArea[0], plotArea[1], "Fit", "Center", "Yes", plotStyleName, "Yes", "As displayed", plotPathname.Replace("\\", "/"), "No", "Yes");
if (!File.Exists(plotPathname))
ed.WriteMessage("Plot Failed: {0}..{1}, {2}", plotArea[0], plotArea[1], plotPathname);
}
}
catch (System.Exception ex)
{
if (ed != null)
ed.WriteMessage("\n Error in MultiPlot: {0}", ex.Message);
}
Application.SetSystemVariable("FILEDIA",1);
}