Message 1 of 4
Plotting files with api doesn't include paper space objects OR viewport
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
I'm trying to implement a plot method and have problems getting correct results. Sometimes I get paperspace objects only, and sometimes I get viewports only. I haven't managed to get both at the same time for some reason... and I don't know what I've done to get different. Seemingly nothing!
Here is my code:
public static void Plot(string filePath, string layoutName, string plotName, string canonicalMediaName, string plotStyleTable)
{
var fileName = Path.GetFileNameWithoutExtension(filePath);
var path = Path.GetDirectoryName(filePath);
var outFilePath = Path.Combine(path, fileName + ".pdf");
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
using (var trans = db.TransactionManager.StartTransaction())
{
HostApplicationServices.WorkingDatabase = db;
LayoutManager.Current.CurrentLayout = layoutName;
var blockTableRecord = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
// Getting the layout object from elided method
Autodesk.AutoCAD.DatabaseServices.Layout currentLayout = LayoutHandler.GetLayout(layoutName);
var plotInfo = new PlotInfo
{
Layout = blockTableRecord.LayoutId
};
var plotSettings = new Autodesk.AutoCAD.DatabaseServices.PlotSettings(currentLayout.ModelType);
plotSettings.CopyFrom(currentLayout);
var plotSettingsValidator = PlotSettingsValidator.Current;
plotSettingsValidator.RefreshLists(plotSettings);
plotSettingsValidator.SetUseStandardScale(plotSettings, true);
plotSettingsValidator.SetStdScaleType(plotSettings, StdScaleType.ScaleToFit);
plotSettingsValidator.SetPlotConfigurationName(plotSettings, plotName, canonicalMediaName);
plotSettingsValidator.SetPlotPaperUnits(plotSettings, PlotPaperUnit.Millimeters);
plotSettingsValidator.SetPlotRotation(plotSettings, PlotRotation.Degrees000);
plotSettingsValidator.SetPlotType(plotSettings, Autodesk.AutoCAD.DatabaseServices.PlotType.Layout);
plotSettingsValidator.SetCustomPrintScale(plotSettings, new CustomScale(1, 1));
plotSettingsValidator.SetCurrentStyleSheet(plotSettings, plotStyleTable);
plotSettings.DrawViewportsFirst = true;
plotSettings.PrintLineweights = true;
plotSettings.ScaleLineweights = true;
var plotInfoValidator = new PlotInfoValidator
{
MediaMatchingPolicy = MatchingPolicy.MatchEnabled
};
plotInfoValidator.Validate(plotInfo);
if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
{
using (var plotEngine = PlotFactory.CreatePublishEngine())
{
// Start plot
plotEngine.BeginPlot(null, null);
plotEngine.BeginDocument(plotInfo, doc.Name, null, 1, true, outFilePath);
plotEngine.BeginPage(new PlotPageInfo(), plotInfo, true, null);
plotEngine.BeginGenerateGraphics(null);
// Finish plot
plotEngine.EndGenerateGraphics(null);
plotEngine.EndPage(null);
plotEngine.EndDocument(null);
plotEngine.EndPlot(null);
}
}
}
}
I have tried to change plotSettings.DrawViewportsFirst to false, but nothing changes...
I don't know what I can do or why I sometimes get the viewport content and sometime only the paperspace content!
Anyone recognizes the problem or has any suggestions?
Thanks!