using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.PlottingServices;
using Autodesk.AutoCAD.EditorInput;
namespace pavps
{
public class pavps
{
[CommandMethod("PAVPS")]
public void Run()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor ed = acDoc.Editor;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
LayoutManager acLayoutMgr = LayoutManager.Current;
Layout acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForRead) as Layout;
acDoc.Editor.WriteMessage("\nCurrent layout: " + acLayout.LayoutName);
acDoc.Editor.WriteMessage("\nCurrent device name: " + acLayout.PlotConfigurationName);
PlotInfo acPlInfo = new PlotInfo();
acPlInfo.Layout = acLayout.ObjectId;
PlotSettings acPlSet = new PlotSettings(false);
acLayout.UpgradeOpen();
acPlSet.CopyFrom(acLayout);
PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
// var plotConfig = acPlInfo.ValidatedConfig;
PlotConfig plotConfig = PlotConfigManager.SetCurrentConfig(acLayout.PlotConfigurationName);
acPlSetVdr.SetPlotConfigurationName(acPlSet, acLayout.PlotConfigurationName, null);
//PlotConfig plotConfig = PlotConfigManager.CurrentConfig;
var canonicalName = acPlSet.CanonicalMediaName;
var localName = plotConfig.GetLocalMediaName(canonicalName);
var mediaBounds = plotConfig.GetMediaBounds(canonicalName);
var pageSize = mediaBounds.PageSize;
var left1 = mediaBounds.LowerLeftPrintableArea;
var right1 = mediaBounds.UpperRightPrintableArea;
Extents3d ext = acLayout.Extents;
Extents2d lim = acLayout.Limits;
ObjectIdCollection vPortsIds = new ObjectIdCollection();
vPortsIds = acLayout.GetViewports();
Viewport viewport = acTrans.GetObject(vPortsIds[0], OpenMode.ForRead) as Viewport;
Extents3d vpExts = viewport.GeometricExtents;
ed.WriteMessage("\n" + vpExts.ToString());
ed.WriteMessage("\n" + ext.ToString());
ed.WriteMessage("\n" + lim.ToString());
ed.WriteMessage("\n" + pageSize.X.ToString());
ed.WriteMessage("\n" + pageSize.Y.ToString());
ed.WriteMessage("\n" + left1.X.ToString());
ed.WriteMessage("\n" + left1.Y.ToString());
ed.WriteMessage("\n" + right1.X.ToString());
ed.WriteMessage("\n" + right1.Y.ToString());
ed.WriteMessage("\n" + canonicalName.ToString());
ed.WriteMessage("\n" + localName.ToString());
acTrans.Commit();
}
}
}
}