<?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: ArcGIS Pro Export Layout to Desktop Button in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/arcgis-pro-export-layout-to-desktop-button/m-p/1315260#M10140</link>
    <description>&lt;P&gt;Also when changing the filepath an error shows up when pressing the button that shows "ArcGIS.Core.CalledOnWrongThreadException: 'This method or property must be called on the thread this object was created on." on the layout.Export(pdf) line of code. Any help would be greatly appreciated. Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 03 Aug 2023 19:44:59 GMT</pubDate>
    <dc:creator>WilliamHart1</dc:creator>
    <dc:date>2023-08-03T19:44:59Z</dc:date>
    <item>
      <title>ArcGIS Pro Export Layout to Desktop Button</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/arcgis-pro-export-layout-to-desktop-button/m-p/1315217#M10138</link>
      <description>&lt;P&gt;Hello all - I am trying to create a plug in button in Pro that takes the current layout view and exports the layout to the desktop. When I go to press the button the code runs with no problem but I am not receiving any output. If anybody could help - I would really appreciate it. Thank you.&lt;/P&gt;&lt;P&gt;Code below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using ArcGIS.Core.CIM;&lt;BR /&gt;using ArcGIS.Core.Data;&lt;BR /&gt;using ArcGIS.Core.Geometry;&lt;BR /&gt;using ArcGIS.Desktop.Catalog;&lt;BR /&gt;using ArcGIS.Desktop.Core;&lt;BR /&gt;using ArcGIS.Desktop.Editing;&lt;BR /&gt;using ArcGIS.Desktop.Extensions;&lt;BR /&gt;using ArcGIS.Desktop.Framework;&lt;BR /&gt;using ArcGIS.Desktop.Framework.Contracts;&lt;BR /&gt;using ArcGIS.Desktop.Framework.Dialogs;&lt;BR /&gt;using ArcGIS.Desktop.Framework.Threading.Tasks;&lt;BR /&gt;using ArcGIS.Desktop.Layouts;&lt;BR /&gt;using ArcGIS.Desktop.Mapping;&lt;BR /&gt;using System;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.Linq;&lt;BR /&gt;using System.Text;&lt;BR /&gt;using System.Threading.Tasks;&lt;BR /&gt;using static ArcGIS.Desktop.Internal.Core.PortalTrafficDataService.PortalDescriptionResponse;&lt;/P&gt;&lt;P&gt;namespace Export_Button&lt;BR /&gt;{&lt;BR /&gt;internal class Button1 : Button&lt;BR /&gt;{&lt;BR /&gt;protected override async void OnClick()&lt;BR /&gt;{&lt;BR /&gt;LayoutProjectItem layoutItem = Project.Current.GetItems&amp;lt;LayoutProjectItem&amp;gt;().FirstOrDefault(item =&amp;gt; item.Name.Equals("Layout"));&lt;BR /&gt;Layout layout = await QueuedTask.Run(() =&amp;gt; layoutItem.GetLayout());&lt;BR /&gt;String filePath = "//map.pdf";&lt;/P&gt;&lt;P&gt;// cref: ArcGIS.Desktop.Layouts.Layout.Export&lt;BR /&gt;// cref: ARCGIS.DESKTOP.MAPPING.PDFFORMAT&lt;BR /&gt;// cref: ARCGIS.DESKTOP.MAPPING.EXPORTFORMAT&lt;BR /&gt;// cref: ARCGIS.DESKTOP.MAPPING.EXPORTFORMAT.VALIDATEOUTPUTFILEPATH&lt;BR /&gt;// cref: ArcGIS.Desktop.Mapping.PDFFormat.ImageCompression&lt;BR /&gt;// cref: ARCGIS.DESKTOP.MAPPING.PDFFORMAT.IMAGEQUALITY&lt;BR /&gt;// cref: ARCGIS.DESKTOP.MAPPING.PDFFORMAT.LAYERSANDATTRIBUTES&lt;BR /&gt;// cref: ARCGIS.DESKTOP.MAPPING.ImageCompression&lt;BR /&gt;// cref: ARCGIS.DESKTOP.MAPPING.ImageQuality&lt;BR /&gt;// cref: ARCGIS.DESKTOP.MAPPING.LayersAndAttributes&lt;BR /&gt;#region Layout_ExportPDF&lt;BR /&gt;//Export a layout to PDF&lt;/P&gt;&lt;P&gt;//Create a PDF export format&lt;BR /&gt;PDFFormat pdf = new PDFFormat()&lt;BR /&gt;{&lt;BR /&gt;OutputFileName = filePath,&lt;BR /&gt;Resolution = 300,&lt;BR /&gt;DoCompressVectorGraphics = true,&lt;BR /&gt;DoEmbedFonts = true,&lt;BR /&gt;HasGeoRefInfo = true,&lt;BR /&gt;ImageCompression = ImageCompression.Adaptive,&lt;BR /&gt;ImageQuality = ImageQuality.Best,&lt;BR /&gt;LayersAndAttributes = LayersAndAttributes.LayersAndAttributes&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;//Check to see if the path is valid and export&lt;BR /&gt;if (pdf.ValidateOutputFilePath())&lt;BR /&gt;{&lt;BR /&gt;layout.Export(pdf); //Export the PDF&lt;BR /&gt;}&lt;BR /&gt;#endregion Layout_ExportPDF&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 18:38:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/arcgis-pro-export-layout-to-desktop-button/m-p/1315217#M10138</guid>
      <dc:creator>WilliamHart1</dc:creator>
      <dc:date>2023-08-03T18:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro Export Layout to Desktop Button</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/arcgis-pro-export-layout-to-desktop-button/m-p/1315260#M10140</link>
      <description>&lt;P&gt;Also when changing the filepath an error shows up when pressing the button that shows "ArcGIS.Core.CalledOnWrongThreadException: 'This method or property must be called on the thread this object was created on." on the layout.Export(pdf) line of code. Any help would be greatly appreciated. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 19:44:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/arcgis-pro-export-layout-to-desktop-button/m-p/1315260#M10140</guid>
      <dc:creator>WilliamHart1</dc:creator>
      <dc:date>2023-08-03T19:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro Export Layout to Desktop Button</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/arcgis-pro-export-layout-to-desktop-button/m-p/1315276#M10141</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;You need call layout.Export(pdf) on the MCT. It means , it must be enclosed in&amp;nbsp;QueuedTask.Run.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;//Check to see if the path is valid and export
if (pdf.ValidateOutputFilePath())
{
  await QueuedTask.Run(() =&amp;gt;
  {
    layout.Export(pdf); //Export the PDF
  });
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 03 Aug 2023 20:07:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/arcgis-pro-export-layout-to-desktop-button/m-p/1315276#M10141</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2023-08-03T20:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro Export Layout to Desktop Button</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/arcgis-pro-export-layout-to-desktop-button/m-p/1315306#M10142</link>
      <description>&lt;P&gt;Thank you for the response. With that update, there is no map export and the only thing that happens is the script shown below in the output window of Visual Studio. This solution did relieve the "CalledOnWrongThread" error.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"The thread 0x4fe4 has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x333c has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x5ff8 has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x9b8 has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x2b10 has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x6888 has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x563c has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x158c has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x8b8c has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x70cc has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x8b3c has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x4ea0 has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x7694 has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x87bc has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x7ad0 has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x6588 has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x7280 has exited with code 0 (0x0).&lt;BR /&gt;The thread 0x7610 has exited with code 0 (0x0)."&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 21:16:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/arcgis-pro-export-layout-to-desktop-button/m-p/1315306#M10142</guid>
      <dc:creator>WilliamHart1</dc:creator>
      <dc:date>2023-08-03T21:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro Export Layout to Desktop Button</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/arcgis-pro-export-layout-to-desktop-button/m-p/1316002#M10153</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/42133"&gt;@GKmieliauskas&lt;/a&gt;&amp;nbsp; is correct, you have to call the export method from the MCT.&amp;nbsp; Your example code worked fine for after i made a few correction and added some error checking:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected override async void OnClick()
{
  try
  {
    LayoutProjectItem layoutItem = Project.Current.GetItems&amp;lt;LayoutProjectItem&amp;gt;().FirstOrDefault(item =&amp;gt; item.Name.Equals("Layout")) ?? throw new Exception("Layout not found");
    Layout layout = await QueuedTask.Run(() =&amp;gt; layoutItem.GetLayout());
    String filePath = @"c:\temp\map.pdf";

    //Create a PDF export format
    PDFFormat pdf = new()
    {
      OutputFileName = filePath,
      Resolution = 300,
      DoCompressVectorGraphics = true,
      DoEmbedFonts = true,
      HasGeoRefInfo = true,
      ImageCompression = ImageCompression.Adaptive,
      ImageQuality = ImageQuality.Best,
      LayersAndAttributes = LayersAndAttributes.LayersAndAttributes
    };

    //Check to see if the path is valid and export
    if (!pdf.ValidateOutputFilePath())
      throw new Exception($@"Invalid path: {filePath}");
    await QueuedTask.Run(() =&amp;gt; layout.Export(pdf)); //Export the PDF
  }
  catch (Exception ex)
  {
    MessageBox.Show("Error: " + ex.ToString());
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Running the sample code above results in a c:\temp\map.pdf file:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Wolf_0-1691412906493.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/77441iBBF9C439FCC09879/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Wolf_0-1691412906493.png" alt="Wolf_0-1691412906493.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I fixed the ProSnippet so that the Export method is now called from within QueuedTask.Run.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for pointing this out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 13:01:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/arcgis-pro-export-layout-to-desktop-button/m-p/1316002#M10153</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2023-08-07T13:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro Export Layout to Desktop Button</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/arcgis-pro-export-layout-to-desktop-button/m-p/1317103#M10167</link>
      <description>This worked. Thank you!</description>
      <pubDate>Wed, 09 Aug 2023 19:35:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/arcgis-pro-export-layout-to-desktop-button/m-p/1317103#M10167</guid>
      <dc:creator>WilliamHart1</dc:creator>
      <dc:date>2023-08-09T19:35:34Z</dc:date>
    </item>
  </channel>
</rss>

