<?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 Export Bookmarked Frame + Data Driven Frame Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/export-bookmarked-frame-data-driven-frame-python/m-p/708893#M54948</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, Been stuck on this for a few hours wondering if anything can point me in the right direction, I am pretty new to Python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I have is 2 data frames in an MXD.&amp;nbsp; 1 data frame is controlled using data drive pages and the other frame is controlled using bookmarks (has no spatial reference).&amp;nbsp; There are 30+ pages and I have to export each one manually changing book mark to pg1,pg2, pg3..etc and my data driven pages&amp;nbsp; to pg1, pg2, pg3 etc.&amp;nbsp; I am trying to write a python script which will change the data drive page when it changes the bookmark and exports at each loop e.g bookmark pg1 and data drive page pg1 on same page.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is as far as I have managed to get today:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be much appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Cross Section")[0]&amp;nbsp;&amp;nbsp; for bkmk in arcpy.mapping.ListBookmarks(mxd, data_frame=df):&amp;nbsp; df.extent = bkmk.extent&amp;nbsp;&amp;nbsp; for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): &amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum&amp;nbsp; arcpy.mapping.ExportToPNG(mxd, r"D:\\" + str(pageNum) + bkmk.name + ".png")&amp;nbsp;&amp;nbsp; del mxd &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Dec 2013 01:41:37 GMT</pubDate>
    <dc:creator>ShaneHogg</dc:creator>
    <dc:date>2013-12-05T01:41:37Z</dc:date>
    <item>
      <title>Export Bookmarked Frame + Data Driven Frame Python</title>
      <link>https://community.esri.com/t5/python-questions/export-bookmarked-frame-data-driven-frame-python/m-p/708893#M54948</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, Been stuck on this for a few hours wondering if anything can point me in the right direction, I am pretty new to Python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I have is 2 data frames in an MXD.&amp;nbsp; 1 data frame is controlled using data drive pages and the other frame is controlled using bookmarks (has no spatial reference).&amp;nbsp; There are 30+ pages and I have to export each one manually changing book mark to pg1,pg2, pg3..etc and my data driven pages&amp;nbsp; to pg1, pg2, pg3 etc.&amp;nbsp; I am trying to write a python script which will change the data drive page when it changes the bookmark and exports at each loop e.g bookmark pg1 and data drive page pg1 on same page.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is as far as I have managed to get today:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be much appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Cross Section")[0]&amp;nbsp;&amp;nbsp; for bkmk in arcpy.mapping.ListBookmarks(mxd, data_frame=df):&amp;nbsp; df.extent = bkmk.extent&amp;nbsp;&amp;nbsp; for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): &amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum&amp;nbsp; arcpy.mapping.ExportToPNG(mxd, r"D:\\" + str(pageNum) + bkmk.name + ".png")&amp;nbsp;&amp;nbsp; del mxd &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 01:41:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-bookmarked-frame-data-driven-frame-python/m-p/708893#M54948</guid>
      <dc:creator>ShaneHogg</dc:creator>
      <dc:date>2013-12-05T01:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Export Bookmarked Frame + Data Driven Frame Python</title>
      <link>https://community.esri.com/t5/python-questions/export-bookmarked-frame-data-driven-frame-python/m-p/708894#M54949</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think the following code will work better for you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Cross Section")[0]&amp;nbsp; dict={} dict[1] = "Page 1" dict[2] = "Page 2" dict[3] = "Page 3"&amp;nbsp; for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): &amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum&amp;nbsp; &amp;nbsp; bkmk = arcpy.mapping.ListBookmarks(mxd, dict[pageNum], df)[0] &amp;nbsp; df.extent = bkmk.extent&amp;nbsp; &amp;nbsp; arcpy.mapping.ExportToPNG(mxd, r"D:\\" + str(pageNum) + bkmk.name + ".png") del mxd&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here are some comments:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- your code was iterating through all bookmarks for each DDP page.&amp;nbsp; I let DDP be the main driver, and then got the bookmark extent for that particular page.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- If your bookmark names were identical to the page numbers, it could have been even easier code.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Because your page numbers obviously don't match the page names I created a Python dictionary - it stores the translation (I'm assuming a 1:1 relationship between DDP page number [key] and bookmark [value]).&amp;nbsp;&amp;nbsp; You will need to edit the code to increase the number of key/value-pairs in the dictionary.&amp;nbsp; If there is not a 1:1 relationship and there are more pages than bookmarks, then it will error when it advances to the next DDP page and can't find the corresponding bookmark.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- For listBookmarks, we are passing in the dictionary key as the wildcard and it returns the name as the value to do the search on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope this helps and have FUN learning arcpy.mapping!!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 13:56:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-bookmarked-frame-data-driven-frame-python/m-p/708894#M54949</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2013-12-05T13:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: Export Bookmarked Frame + Data Driven Frame Python</title>
      <link>https://community.esri.com/t5/python-questions/export-bookmarked-frame-data-driven-frame-python/m-p/708895#M54950</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey Jeff,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help,&amp;nbsp; In the end I made a few changes just to export of PDF and combine all the pages into 1 PDF file.&amp;nbsp; I also changed the bookmark names to match the data driven pages names as its just easier/automatic for me, but good to know the alternative!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think the next step from here is to create a toolbox and add it so that a user can enter in a output folder and name.&amp;nbsp; Do you know of any esri help files/pages which may be able to help with that?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;code is here if its useful for anyone at this stage:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, os, string
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Cross Section")[0] 
finalPdf = arcpy.mapping.PDFDocumentCreate(r"D:\final.pdf")
tmpPdf = r"D:\TEMP.pdf"

for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
&amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum

&amp;nbsp; bkmk = arcpy.mapping.ListBookmarks(mxd, pageNum, df)[0]
&amp;nbsp; df.extent = bkmk.extent

&amp;nbsp; arcpy.mapping.ExportToPDF(mxd, tmpPdf)
&amp;nbsp; finalPdf.appendPages(tmpPdf)
&amp;nbsp; 
del mxd, tmpPdf

tmpPdf = r"D:\TEMP.pdf"
arcpy.mapping.ExportToPDF(tmpPdf, "ALL")
finalPdf.appendPages(tmpPdf)
del tmpPdf
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:46:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-bookmarked-frame-data-driven-frame-python/m-p/708895#M54950</guid>
      <dc:creator>ShaneHogg</dc:creator>
      <dc:date>2021-12-12T05:46:38Z</dc:date>
    </item>
  </channel>
</rss>

