<?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: Script: export DDP to PDF but sorting by a field in attribute table of Grid Index in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/script-export-ddp-to-pdf-but-sorting-by-a-field-in/m-p/247537#M2635</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Without doing any debugging, the export to PDF line needs an additional quote at the front of CURRENT.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jim&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 21 Aug 2013 13:47:23 GMT</pubDate>
    <dc:creator>JimCousins</dc:creator>
    <dc:date>2013-08-21T13:47:23Z</dc:date>
    <item>
      <title>Script: export DDP to PDF but sorting by a field in attribute table of Grid Index</title>
      <link>https://community.esri.com/t5/mapping-questions/script-export-ddp-to-pdf-but-sorting-by-a-field-in/m-p/247536#M2634</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am new to scripting and I hit a wall at every turn. What am I doing wrong? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are two parameters:&amp;nbsp; 1) Select Map Document to Print,&amp;nbsp;&amp;nbsp; 2) Select Output File Location&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy, os, sys, string&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Read input parameters from script tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxdPath = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outputlocation = arcpy.GetParameterAsText(1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Reference the map and the data driven page object&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(mxdPath)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get the row from the attribute table of the index layer &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; row = mxd.dataDrivenPages.pageRow&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; # Get the value from the field called PageName&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; name = row.getValue("PageName")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; # Concatenate into whole path name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; outputName = outputlocation + "\\" + name + "_ArcMap" + ".pdf"&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; # Export to PDF&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ddp.exportToPDF (outputName, CURRENT",1,"PDF_SINGLE_FILE",300,"BEST","RGB",1,"ADAPTIVE","RASTERIZE_BITMAP",0,1,"LAYERS_ONLY",1,80)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Clean up&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del mxd&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Untimately I want to build on it and do a filter so I only print pages that pass the query "Type" LIKE 'Vertical Map'. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have tried it a couple of ways and I am lost in the weeds.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Aug 2013 18:05:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/script-export-ddp-to-pdf-but-sorting-by-a-field-in/m-p/247536#M2634</guid>
      <dc:creator>YanetCuddus</dc:creator>
      <dc:date>2013-08-14T18:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: Script: export DDP to PDF but sorting by a field in attribute table of Grid Index</title>
      <link>https://community.esri.com/t5/mapping-questions/script-export-ddp-to-pdf-but-sorting-by-a-field-in/m-p/247537#M2635</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Without doing any debugging, the export to PDF line needs an additional quote at the front of CURRENT.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jim&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Aug 2013 13:47:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/script-export-ddp-to-pdf-but-sorting-by-a-field-in/m-p/247537#M2635</guid>
      <dc:creator>JimCousins</dc:creator>
      <dc:date>2013-08-21T13:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Script: export DDP to PDF but sorting by a field in attribute table of Grid Index</title>
      <link>https://community.esri.com/t5/mapping-questions/script-export-ddp-to-pdf-but-sorting-by-a-field-in/m-p/247538#M2636</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;For a project I did, I added a numeric "PageOrder" field to the Index Layer. I set it as the DDP Sort field and just mirrored the DDP page numbers. I then use a Search Cursor to to filter and sort the pages.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So for an index layer something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[TABLE="class: grid, width: 30%"]ObjectID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PageName&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Type&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PageOrder&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Shape&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Page_1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Type1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;14&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Page_2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Type2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;6&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Page_3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Type1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[/TABLE]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
mainPDF = r"c:\yourPath\pdfname.pdf"
pdf = arcpy.mapping.PDFDocumentCreate(mainPDF) #Generate pdf to hold the pages

#create a Search Cursor that filters to the pages you want &amp;amp; sorts on a field
pageList = arcpy.SearchCursor(indexLayer, "\"Type\" = 'Type1'", None, None, "PageOrder A;")

for page in pageList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; pageNum = page.getValue("PageOrder") 
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum #set the DDP page number

&amp;nbsp;&amp;nbsp;&amp;nbsp; tempPDF = "c:\\tempPath\\{0}.pdf".format(str(page.getValue("PageName")))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(mxd, tempPDF) #generate pdf of page

&amp;nbsp;&amp;nbsp;&amp;nbsp; mainPDF.appendPages(tempPDF) #add the page to the main pdf

mainPDF.saveAndClose()
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;NOTE: This is for 10.0. If you're on 10.1 or newer there are new 'da' cursors (i.e. arcpy.da.SearchCursor(...)) which are more efficient. Be aware that the parameters are set up a little differently though. Also, generally a good idea to check if a pdf already exists before creating it. Left that out as not to detract.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I suspect there are more elegant ways to do this though. The way I do it, if I insert an index feature somewhere in the middle of the pack, I have to manually shift the "PageOrder" values to accomidate. Not difficult, but it's manual and one more step to remember to do.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:19:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/script-export-ddp-to-pdf-but-sorting-by-a-field-in/m-p/247538#M2636</guid>
      <dc:creator>MattSayler</dc:creator>
      <dc:date>2021-12-11T12:19:23Z</dc:date>
    </item>
  </channel>
</rss>

