<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Plotting files with api doesn't include paper space objects OR viewport in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/plotting-files-with-api-doesn-t-include-paper-space-objects-or/m-p/10319962#M16472</link>
    <description>&lt;P&gt;Might have something to do with you're &lt;STRONG&gt;layoutId&lt;/STRONG&gt; assignment to PlotInfo.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;...
var lm = LayoutManager.Current;
lm.CurrentLayout = layoutName;
var layoutId = lm.GetLayoutId(layoutName);
plotInfo.Layout = layoutId;
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Simplified copy of Layout2Pdf -- without the PlotSettings changes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;public static void Layout2Pdf(ObjectId layoutId, string pdfPathname)
{
Document doc = null;
LayoutManager lm = null;
try
{
if (layoutId.IsNull)
throw new System.Exception($"Invalid Argument: {nameof(layoutId)} IS NULL");

if (string.IsNullOrWhiteSpace(pdfPathname))
throw new System.Exception($"Invalid Argument: {nameof(pdfPathname)} IS NULL");

var db = layoutId.Database;
if (db == null)
throw new System.Exception($"Not in DB: {nameof(layoutId)} ");

doc = AcadApp.DocumentManager.GetDocument(db);
lm = LayoutManager.Current;
lm.SetCurrentLayoutId(layoutId);

if (File.Exists(pdfPathname))
File.Delete(pdfPathname);

var psv = PlotSettingsValidator.Current;
using (var plotInfo = new PlotInfo())
{
using (var plotEngine = PlotFactory.CreatePublishEngine())
{
plotEngine.BeginPlot(null, null);
var validator = new PlotInfoValidator()
{
MediaMatchingPolicy = Autodesk.AutoCAD.PlottingServices.MatchingPolicy.MatchEnabled
};
plotInfo.Layout = layoutId;
validator.Validate(plotInfo);
plotEngine.BeginDocument(plotInfo, doc.Name, null, 1, true, pdfPathname);
using (var pageInfo = new PlotPageInfo())
{
plotEngine.BeginPage(pageInfo, plotInfo, true, null);
}
plotEngine.BeginGenerateGraphics(null);
plotEngine.EndGenerateGraphics(null);
plotEngine.EndPage(null);
plotEngine.EndDocument(null);
plotEngine.EndPlot(null);
}
}
if (!File.Exists(pdfPathname))
{
throw new System.Exception($"Create PDF failed ");
}
}
catch (System.Exception ex)
{
throw;
}
}&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 18 May 2021 06:02:59 GMT</pubDate>
    <dc:creator>SENL1362</dc:creator>
    <dc:date>2021-05-18T06:02:59Z</dc:date>
    <item>
      <title>Plotting files with api doesn't include paper space objects OR viewport</title>
      <link>https://forums.autodesk.com/t5/net-forum/plotting-files-with-api-doesn-t-include-paper-space-objects-or/m-p/10305349#M16471</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="plot-empty-viewport.png" style="width: 500px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/917556i468A89F4B343995A/image-size/large?v=v2&amp;amp;px=999" role="button" title="plot-empty-viewport.png" alt="plot-empty-viewport.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="plot-no-paperspace-objects.png" style="width: 500px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/917557i2893FB138765B592/image-size/large?v=v2&amp;amp;px=999" role="button" title="plot-no-paperspace-objects.png" alt="plot-no-paperspace-objects.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;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);
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to change plotSettings.DrawViewportsFirst&amp;nbsp; to false, but nothing changes...&lt;/P&gt;&lt;P&gt;I don't know what I can do or why I sometimes get the viewport content and sometime only the paperspace content!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone recognizes the problem or has any suggestions?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 13:09:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plotting-files-with-api-doesn-t-include-paper-space-objects-or/m-p/10305349#M16471</guid>
      <dc:creator>ottosson_mathias</dc:creator>
      <dc:date>2021-05-11T13:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting files with api doesn't include paper space objects OR viewport</title>
      <link>https://forums.autodesk.com/t5/net-forum/plotting-files-with-api-doesn-t-include-paper-space-objects-or/m-p/10319962#M16472</link>
      <description>&lt;P&gt;Might have something to do with you're &lt;STRONG&gt;layoutId&lt;/STRONG&gt; assignment to PlotInfo.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;...
var lm = LayoutManager.Current;
lm.CurrentLayout = layoutName;
var layoutId = lm.GetLayoutId(layoutName);
plotInfo.Layout = layoutId;
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Simplified copy of Layout2Pdf -- without the PlotSettings changes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;public static void Layout2Pdf(ObjectId layoutId, string pdfPathname)
{
Document doc = null;
LayoutManager lm = null;
try
{
if (layoutId.IsNull)
throw new System.Exception($"Invalid Argument: {nameof(layoutId)} IS NULL");

if (string.IsNullOrWhiteSpace(pdfPathname))
throw new System.Exception($"Invalid Argument: {nameof(pdfPathname)} IS NULL");

var db = layoutId.Database;
if (db == null)
throw new System.Exception($"Not in DB: {nameof(layoutId)} ");

doc = AcadApp.DocumentManager.GetDocument(db);
lm = LayoutManager.Current;
lm.SetCurrentLayoutId(layoutId);

if (File.Exists(pdfPathname))
File.Delete(pdfPathname);

var psv = PlotSettingsValidator.Current;
using (var plotInfo = new PlotInfo())
{
using (var plotEngine = PlotFactory.CreatePublishEngine())
{
plotEngine.BeginPlot(null, null);
var validator = new PlotInfoValidator()
{
MediaMatchingPolicy = Autodesk.AutoCAD.PlottingServices.MatchingPolicy.MatchEnabled
};
plotInfo.Layout = layoutId;
validator.Validate(plotInfo);
plotEngine.BeginDocument(plotInfo, doc.Name, null, 1, true, pdfPathname);
using (var pageInfo = new PlotPageInfo())
{
plotEngine.BeginPage(pageInfo, plotInfo, true, null);
}
plotEngine.BeginGenerateGraphics(null);
plotEngine.EndGenerateGraphics(null);
plotEngine.EndPage(null);
plotEngine.EndDocument(null);
plotEngine.EndPlot(null);
}
}
if (!File.Exists(pdfPathname))
{
throw new System.Exception($"Create PDF failed ");
}
}
catch (System.Exception ex)
{
throw;
}
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 18 May 2021 06:02:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plotting-files-with-api-doesn-t-include-paper-space-objects-or/m-p/10319962#M16472</guid>
      <dc:creator>SENL1362</dc:creator>
      <dc:date>2021-05-18T06:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting files with api doesn't include paper space objects OR viewport</title>
      <link>https://forums.autodesk.com/t5/net-forum/plotting-files-with-api-doesn-t-include-paper-space-objects-or/m-p/10320105#M16473</link>
      <description>&lt;P&gt;Thanks, but unfortunately&lt;/P&gt;&lt;LI-CODE lang="general"&gt;LayoutManager.Current.CurrentLayout = layoutName;&lt;/LI-CODE&gt;&lt;P&gt;vs&lt;/P&gt;&lt;LI-CODE lang="general"&gt;LayoutManager.Current.SetCurrentLayoutId(layoutId);&lt;/LI-CODE&gt;&lt;P&gt;did not make any difference...&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 07:16:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plotting-files-with-api-doesn-t-include-paper-space-objects-or/m-p/10320105#M16473</guid>
      <dc:creator>ottosson_mathias</dc:creator>
      <dc:date>2021-05-18T07:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting files with api doesn't include paper space objects OR viewport</title>
      <link>https://forums.autodesk.com/t5/net-forum/plotting-files-with-api-doesn-t-include-paper-space-objects-or/m-p/10320112#M16474</link>
      <description>&lt;P&gt;It's not the Set Layout but the LayoutId assignment to PlotInfo what looks suspicions to me.&lt;/P&gt;&lt;P&gt;My advise:&lt;/P&gt;&lt;P&gt;0. Create the Layout with the required PlotSettings manually.&lt;/P&gt;&lt;P&gt;1. Then create the PDF without the PlotSettings modifications and use the first four assignments.&lt;/P&gt;&lt;P&gt;2. Then when a valid PDF has been made, Add The PlotSettings modifications.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 07:23:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plotting-files-with-api-doesn-t-include-paper-space-objects-or/m-p/10320112#M16474</guid>
      <dc:creator>SENL1362</dc:creator>
      <dc:date>2021-05-18T07:23:28Z</dc:date>
    </item>
  </channel>
</rss>

