using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.PlottingServices;
[CommandMethod("CreateOrEditPageSetup")]
public static void CreateOrEditPageSetup()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
DBDictionary plSets = acTrans.GetObject(acCurDb.PlotSettingsDictionaryId,
OpenMode.ForRead) as DBDictionary;
DBDictionary vStyles = acTrans.GetObject(acCurDb.VisualStyleDictionaryId,
OpenMode.ForRead) as DBDictionary;
PlotSettings acPlSet = default(PlotSettings);
bool createNew = false;
LayoutManager acLayoutMgr = LayoutManager.Current;
Layout acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout),
OpenMode.ForRead) as Layout;
if (plSets.Contains("MyPageSetup") == false)
{
createNew = true;
acPlSet = new PlotSettings(acLayout.ModelType);
acPlSet.CopyFrom(acLayout);
acPlSet.PlotSettingsName = "MyPageSetup";
acPlSet.AddToPlotSettingsDictionary(acCurDb);
acTrans.AddNewlyCreatedDBObject(acPlSet, true);
}
else
{
acPlSet = plSets.GetAt("MyPageSetup").GetObject(OpenMode.ForWrite) as PlotSettings;
}
try
{
PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", "A1");
if (acLayout.ModelType == false)
{
acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Layout);
}
else
{
acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
acPlSetVdr.SetPlotCentered(acPlSet, true);
}
acPlSetVdr.SetPlotOrigin(acPlSet, new Point2d(0, 0));
acPlSetVdr.SetUseStandardScale(acPlSet, true);
acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit);
acPlSetVdr.SetPlotPaperUnits(acPlSet, PlotPaperUnit.Inches);
acPlSet.ScaleLineweights = true;
acPlSet.ShowPlotStyles = true;
acPlSetVdr.RefreshLists(acPlSet);
acPlSet.ShadePlot = PlotSettingsShadePlotType.AsDisplayed;
acPlSet.ShadePlotResLevel = ShadePlotResLevel.Normal;
acPlSet.PrintLineweights = true;
acPlSet.PlotTransparency = false;
acPlSet.PlotPlotStyles = true;
acPlSet.DrawViewportsFirst = true;
acPlSet.CurrentStyleSheet
acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees000);
if (acCurDb.PlotStyleMode == true)
{
acPlSetVdr.SetCurrentStyleSheet(acPlSet, "acad.ctb");
}
else
{
acPlSetVdr.SetCurrentStyleSheet(acPlSet, "acad.stb");
}
acPlSetVdr.SetZoomToPaperOnUpdate(acPlSet, true);
}
catch (Autodesk.AutoCAD.Runtime.Exception es)
{
System.Windows.Forms.MessageBox.Show(es.Message);
}
acTrans.Commit();
if (createNew == true)
{
acPlSet.Dispose();
}
}
}