Plot to file error !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello! Everyone.
To plot to file, I'm customizing sample source code.
But, I can't set the value, config.IsPlotToFile = true; because plotInfo.ValidatedConfig is null.
I would be very appreciated if you could give me clue how to handle this issue.
Source code is as below.
public static void exPlotToFile()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
string currentFolder = Path.GetDirectoryName(doc.Name);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// We'll be plotting the current layout
BlockTableRecord currentSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
Layout layout = (Layout)tr.GetObject(currentSpace.LayoutId, OpenMode.ForRead);
// PlotInfo object linked to the layout
PlotInfo plotInfo = new PlotInfo();
plotInfo.Layout = currentSpace.LayoutId;
// Set the PlotSettings object based on the layout settings
PlotSettings plotSettings = new PlotSettings(layout.ModelType);
plotSettings.CopyFrom(layout);
// The PlotSettingsValidator helps
// create a valid PlotSettings object
PlotSettingsValidator plotSettingsValidator = PlotSettingsValidator.Current;
PlotConfigManager.RefreshList(RefreshCode.All);
// scaled to fit
plotSettingsValidator.SetPlotType(plotSettings, PlotType.Extents);
plotSettingsValidator.SetUseStandardScale(plotSettings, true);
plotSettingsValidator.SetStdScaleType(plotSettings, StdScaleType.ScaleToFit);
plotSettingsValidator.SetPlotCentered(plotSettings, true);
// Use standard DWF PC3, as
// for today we're just plotting to file
plotSettingsValidator.SetPlotConfigurationName(plotSettings, "DWF6 ePlot.pc3", "ISO A4 (297 x 210 MM)");
plotSettingsValidator.SetCurrentStyleSheet(plotSettings, "Icad.ctb");
plotInfo.OverrideSettings = plotSettings;
PlotInfoValidator plotInfoValidator = new PlotInfoValidator();
plotInfoValidator.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
plotInfoValidator.Validate(plotInfo);
// A PlotEngine does the actual plotting
// (can also create one for Preview)
if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
{
try
{
PlotEngine plotEngine = PlotFactory.CreatePublishEngine();
plotEngine.BeginPlot(null, null);
==> null Value PlotConfig config = plotInfo.ValidatedConfig;
config.IsPlotToFile = true;
plotEngine.BeginDocument(plotInfo, "TestPrint", null, 1, true, Path.Combine(currentFolder, "TestPrint" + plotInfo.ValidatedConfig.DefaultFileExtension));
PlotPageInfo plotPageInfo = new PlotPageInfo();
plotEngine.BeginPage(plotPageInfo, plotInfo, true, null);
plotEngine.BeginGenerateGraphics(null);
plotEngine.EndGenerateGraphics(null);
plotEngine.EndPage(null);
plotEngine.EndDocument(null);
plotEngine.EndPlot(null);
plotEngine.Destroy();
plotEngine = null;
}
catch (System.Exception error) { System.Exception Err = error; }
}
else
{
ed.WriteMessage("\nAnother plot is in progress.");
}
}
}