public void SetLayoutPlotSetting()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
StandartCopier standartCopier = new StandartCopier();
PlotConfigManager.SetCurrentConfig(standartCopier.Pc3Location);
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
Layout acLayout;
var layouts = LayoutModels.OrderBy(x => x.Layout.TabOrder).ToList();
foreach (var layout in layouts)
{
acLayout = acTrans.GetObject(layout.LayoutPlotId,
OpenMode.ForRead) as Layout;
if (acLayout == null) continue;
var plotArea = acLayout.Extents;
// Output the name of the current layout and its device
acDoc.Editor.WriteMessage("\nCurrent layout: " +
acLayout.LayoutName);
acDoc.Editor.WriteMessage("\nCurrent device name: " +
acLayout.PlotConfigurationName);
// Get the PlotInfo from the layout
PlotInfo acPlInfo = new PlotInfo();
acPlInfo.Layout = acLayout.ObjectId;
// Get a copy of the PlotSettings from the layout
PlotSettings acPlSet = new PlotSettings(acLayout.ModelType);
acPlSet.CopyFrom(acLayout);
// Update the PlotConfigurationName property of the PlotSettings object
PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
//acPlSetVdr.SetCurrentStyleSheet(acPlSet, "monochrome.ctb");
bool isHor = layout.PrintModel.IsFormatHorizontal();
acPlSetVdr.SetPlotType(acPlSet, PlotType.Extents);
acPlSetVdr.SetPlotRotation(acPlSet, isHor ? PlotRotation.Degrees000 : PlotRotation.Degrees090);
acPlSetVdr.SetPlotWindowArea(acPlSet, Get2dExtentsFrom3d(plotArea));
acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit);
// Center the plot
acPlSetVdr.SetPlotCentered(acPlSet, true);
acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG_To_PDF_Uzle.pc3",
layout.CanonicalName);
acPlSetVdr.SetZoomToPaperOnUpdate(acPlSet, true);
// Update the layout
acLayout.UpgradeOpen();
acLayout.CopyFrom(acPlSet);
//TODO refresh layout
// Output the name of the new device assigned to the layout
acDoc.Editor.WriteMessage("\nNew device name: " +
acLayout.PlotConfigurationName);
Active.Editor.Regen();
}
// Save the new objects to the database
acTrans.Commit();
}
}