using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using System.IO;
using Autodesk.AutoCAD.PlottingServices;
namespace ClassTest
{
public class ClassTest
{
[CommandMethod("PAVPLOT")]
public void PAVPLOT()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
string path = Path.GetDirectoryName(doc.Name);
string name = Path.GetFileNameWithoutExtension(doc.Name);
// LayoutManager acLayoutMgr = acLayoutMgr = LayoutManager.Current;
using (Transaction acTrans = db.TransactionManager.StartTransaction())
{
DBDictionary dbl = acTrans.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;
// Layout acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId("1"), OpenMode.ForRead) as Layout;
Layout acLayout = acTrans.GetObject(dbl.GetAt("1"), OpenMode.ForRead) as Layout;
// Get the PlotInfo from the layout
PlotInfo acPlInfo = new PlotInfo();
acPlInfo.Layout = acLayout.ObjectId;
//PlotSettings acPlSet = new PlotSettings(acLayout.ModelType);
//acPlSet.CopyFrom(acLayout);
//PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
//acLayout.UpgradeOpen();
//acLayout.CopyFrom(acPlSet);
// Validate the plot info
PlotInfoValidator acPlInfoVdr = new PlotInfoValidator();
acPlInfoVdr.Validate(acPlInfo);
if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
{
using (PlotEngine acPlEng = PlotFactory.CreatePublishEngine())
{
acPlEng.BeginPlot(null, null);
// Define the plot output
acPlEng.BeginDocument(acPlInfo,
doc.Name,
null,
1,
true,
path + @"\" + name + "_" + acLayout.LayoutName);
// Plot the first sheet/layout
PlotPageInfo acPlPageInfo = new PlotPageInfo();
acPlEng.BeginPage(acPlPageInfo,
acPlInfo,
true,
null);
acPlEng.BeginGenerateGraphics(null);
acPlEng.EndGenerateGraphics(null);
// Finish plotting the sheet/layout
acPlEng.EndPage(null);
// Finish plotting the document
acPlEng.EndDocument(null);
// Finish the plot
acPlEng.EndPlot(null);
}
}
acTrans.Commit();
}
}
}
}