<?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 MXD export to PDF using Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/mxd-export-to-pdf-using-python/m-p/1004600#M59117</link>
    <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I am new to Python coding, but somehow managed to put together a simple code by looking at others code available online.&lt;/P&gt;&lt;P&gt;What I want to achieve: A user should select a custom designed template MXD which initially will be loaded only with basemap layers. Then the user will add a raster file from local path to the MXD. User will Type in the Name of the Raster Layer to be displayed in TOC. Then the code will export the MXD to a PDF file.&lt;/P&gt;&lt;P&gt;Below mentioned code works well when I run it in the same MXD's Python command window.&lt;/P&gt;&lt;P&gt;mxdPath = r"&lt;U&gt;C:\MXD.mxd&lt;/U&gt;" &lt;U&gt;#Paratmeter 1&lt;/U&gt;&lt;BR /&gt;... rasterPath = r"&lt;U&gt;C:\Raster.tft&lt;/U&gt;" &lt;U&gt;#Paratmeter 2&lt;/U&gt;&lt;BR /&gt;... mxd = arcpy.mapping.MapDocument(mxdPath)&lt;BR /&gt;... df = arcpy.mapping.ListDataFrames(mxd)[0]&lt;BR /&gt;... result = arcpy.MakeRasterLayer_management(rasterPath,"&lt;U&gt;Raster Layer Name&lt;/U&gt;") &lt;U&gt;#Parameter 3&lt;/U&gt;&lt;BR /&gt;... layer = result.getOutput(0)&lt;BR /&gt;... arcpy.mapping.AddLayer(df,layer, 'AUTO_ARRANGE')&lt;BR /&gt;... arcpy.mapping.ExportToPDF(mxd,r"&lt;U&gt;C:\Test.pdf&lt;/U&gt;") &lt;U&gt;#Parameter 4&lt;/U&gt;&lt;/P&gt;&lt;P&gt;I have two queries, and will really appreciate if someone can guide me in the right direction.&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. How can I let user update the 4 parameters in the code without opening the code&lt;/P&gt;&lt;P&gt;I have seen online add parameters while adding script in the tool box but not sure how to pass them in the code.&lt;/P&gt;&lt;P&gt;&lt;U&gt;Required Parameters&amp;nbsp;&lt;/U&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Input Template MXD Path&lt;/LI&gt;&lt;LI&gt;Input Raster File Path&lt;/LI&gt;&lt;LI&gt;Input Type Raster File Name (To be entered by the User to update in TOC)&lt;/LI&gt;&lt;LI&gt;Output PDF path&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;2. Is it possible to rename the PDF as per the Raster File Name the user types in the parameter 3&lt;/P&gt;&lt;P&gt;Will really appreciate any help and pointers in the right direction.&lt;/P&gt;&lt;P&gt;Thanks and Regards,&lt;/P&gt;&lt;P&gt;Ajinkya&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Nov 2020 08:57:42 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2020-11-25T08:57:42Z</dc:date>
    <item>
      <title>MXD export to PDF using Python</title>
      <link>https://community.esri.com/t5/python-questions/mxd-export-to-pdf-using-python/m-p/1004600#M59117</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I am new to Python coding, but somehow managed to put together a simple code by looking at others code available online.&lt;/P&gt;&lt;P&gt;What I want to achieve: A user should select a custom designed template MXD which initially will be loaded only with basemap layers. Then the user will add a raster file from local path to the MXD. User will Type in the Name of the Raster Layer to be displayed in TOC. Then the code will export the MXD to a PDF file.&lt;/P&gt;&lt;P&gt;Below mentioned code works well when I run it in the same MXD's Python command window.&lt;/P&gt;&lt;P&gt;mxdPath = r"&lt;U&gt;C:\MXD.mxd&lt;/U&gt;" &lt;U&gt;#Paratmeter 1&lt;/U&gt;&lt;BR /&gt;... rasterPath = r"&lt;U&gt;C:\Raster.tft&lt;/U&gt;" &lt;U&gt;#Paratmeter 2&lt;/U&gt;&lt;BR /&gt;... mxd = arcpy.mapping.MapDocument(mxdPath)&lt;BR /&gt;... df = arcpy.mapping.ListDataFrames(mxd)[0]&lt;BR /&gt;... result = arcpy.MakeRasterLayer_management(rasterPath,"&lt;U&gt;Raster Layer Name&lt;/U&gt;") &lt;U&gt;#Parameter 3&lt;/U&gt;&lt;BR /&gt;... layer = result.getOutput(0)&lt;BR /&gt;... arcpy.mapping.AddLayer(df,layer, 'AUTO_ARRANGE')&lt;BR /&gt;... arcpy.mapping.ExportToPDF(mxd,r"&lt;U&gt;C:\Test.pdf&lt;/U&gt;") &lt;U&gt;#Parameter 4&lt;/U&gt;&lt;/P&gt;&lt;P&gt;I have two queries, and will really appreciate if someone can guide me in the right direction.&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. How can I let user update the 4 parameters in the code without opening the code&lt;/P&gt;&lt;P&gt;I have seen online add parameters while adding script in the tool box but not sure how to pass them in the code.&lt;/P&gt;&lt;P&gt;&lt;U&gt;Required Parameters&amp;nbsp;&lt;/U&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Input Template MXD Path&lt;/LI&gt;&lt;LI&gt;Input Raster File Path&lt;/LI&gt;&lt;LI&gt;Input Type Raster File Name (To be entered by the User to update in TOC)&lt;/LI&gt;&lt;LI&gt;Output PDF path&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;2. Is it possible to rename the PDF as per the Raster File Name the user types in the parameter 3&lt;/P&gt;&lt;P&gt;Will really appreciate any help and pointers in the right direction.&lt;/P&gt;&lt;P&gt;Thanks and Regards,&lt;/P&gt;&lt;P&gt;Ajinkya&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 08:57:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/mxd-export-to-pdf-using-python/m-p/1004600#M59117</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-11-25T08:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: MXD export to PDF using Python</title>
      <link>https://community.esri.com/t5/python-questions/mxd-export-to-pdf-using-python/m-p/1004613#M59118</link>
      <description>&lt;P&gt;You just need&amp;nbsp; define the parameters e.g.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;mxdPath = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;rasterPath =&amp;nbsp;arcpy.GetParameterAsText(1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;and so on..&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Then you just create a script tool for it and define the parameter types in the options of the tool.&amp;nbsp; When the tool opens, those defined parameters will be there.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/arcpy/geoprocessing_and_python/adding-a-script-tool.htm" target="_blank"&gt;Add a script tool—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://desktop.arcgis.com/en/arcmap/10.3/analyze/creating-tools/a-quick-tour-of-creating-script-tools.htm" target="_blank"&gt;What is a script tool?—Help | ArcGIS for Desktop&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 09:36:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/mxd-export-to-pdf-using-python/m-p/1004613#M59118</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-11-25T09:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: MXD export to PDF using Python</title>
      <link>https://community.esri.com/t5/python-questions/mxd-export-to-pdf-using-python/m-p/1004619#M59119</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;&lt;P&gt;Thanks a lot of your response and suggestion. I will try this.&lt;/P&gt;&lt;P&gt;Much appreciated!!&lt;/P&gt;&lt;P&gt;Ajinkya&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 10:46:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/mxd-export-to-pdf-using-python/m-p/1004619#M59119</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-11-25T10:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: MXD export to PDF using Python</title>
      <link>https://community.esri.com/t5/python-questions/mxd-export-to-pdf-using-python/m-p/1004627#M59120</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;&lt;P&gt;It worked !!!&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt; , you are best.&lt;/P&gt;&lt;P&gt;One last query is there anyway I can refresh the Layout or TOC in the template MXD to make it ready for next run.&lt;/P&gt;&lt;P&gt;Some how the old raster layers Legend is still getting printed along with new raster layer legend in the output PDF, even if the old raster layer is not there in TOC.&lt;/P&gt;&lt;P&gt;Below is the modified code.&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;from arcpy import env&lt;/P&gt;&lt;P&gt;#pass the product mxd into the script as an input parameter&lt;BR /&gt;mxdPath = arcpy.GetParameterAsText(0)&lt;/P&gt;&lt;P&gt;#Input parameter value Raster path&lt;BR /&gt;rasterPath = arcpy.GetParameterAsText(1)&lt;/P&gt;&lt;P&gt;#Input Raster Layer Name Text&lt;BR /&gt;Rastername = arcpy.GetParameterAsText(2)&lt;/P&gt;&lt;P&gt;#OutputPDF&lt;BR /&gt;pdfname = arcpy.GetParameterAsText(3)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;mxd = arcpy.mapping.MapDocument(mxdPath)&lt;BR /&gt;df = arcpy.mapping.ListDataFrames(mxd)[0]&lt;BR /&gt;result = arcpy.MakeRasterLayer_management(rasterPath, Rastername)&lt;BR /&gt;layer = result.getOutput(0)&lt;BR /&gt;arcpy.mapping.AddLayer(df,layer, 'AUTO_ARRANGE')&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd,pdfname)&lt;/P&gt;&lt;P&gt;Thanks again for your valuable suggestion.&lt;/P&gt;&lt;P&gt;Ajinkya&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 11:46:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/mxd-export-to-pdf-using-python/m-p/1004627#M59120</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-11-25T11:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: MXD export to PDF using Python</title>
      <link>https://community.esri.com/t5/python-questions/mxd-export-to-pdf-using-python/m-p/1004638#M59121</link>
      <description>&lt;P&gt;you might try&amp;nbsp;&lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;RefreshActiveView&lt;/SPAN&gt;&lt;SPAN class="p"&gt;()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;but i'll have&amp;nbsp; look at the code properly when I get the chance.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 12:50:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/mxd-export-to-pdf-using-python/m-p/1004638#M59121</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-11-25T12:50:38Z</dc:date>
    </item>
  </channel>
</rss>

