<?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 Create TPK using Data Driven Pages in ArcMap Questions</title>
    <link>https://community.esri.com/t5/arcmap-questions/create-tpk-using-data-driven-pages/m-p/1110977#M3112</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I am trying to use Data Driven Pages to create Tile packages (TPK) instead of outputting to a PDF or JPG.&amp;nbsp; What I am finding that as I iterate through the pages, the TPK's don't honor the definition query set by the Data Driven Page.&amp;nbsp; In my use case, I am iterating through every floor of a building and trying to write out a TPK (instead of PDF) for every floor.&lt;/P&gt;&lt;P&gt;Is this possible or can you only export to an image?&lt;/P&gt;&lt;P&gt;Here is my Python Script:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os, argparse
parser = argparse.ArgumentParser(description='Export TPK')
parser.add_argument('-inMXD', help='input map document setup for DDP', required=True)
parser.add_argument('-outFolder', help='output folder name where TPKs will be written', required=True)
args = parser.parse_args()

strOutpath = args.outFolder
mxdPath = args.inMXD


#Test if inMXD exists
if os.path.isfile(mxdPath) and os.access(mxdPath, os.R_OK):
  print "input MXD found ( " + mxdPath + ")"
else:
  print "Can NOT find input MXD: " + mxdPath
  exit()

#Test if outFolder exists
if os.path.exists(strOutpath) and os.access(strOutpath, os.W_OK):
  print "Output folder found (" + strOutpath + ")"
else:
  print "Can NOT find output DDP folder:" + strOutpath
  exit()

mxd = arcpy.mapping.MapDocument(mxdPath)

for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
  mxd.dataDrivenPages.currentPageID = pageNum
  pageorder = mxd.dataDrivenPages.pageRow.FloorID
  #Building Value
  buildingVal = mxd.dataDrivenPages.pageRow.getValue("BUILDINGNAME")
  #Floor Value
  floorVal = mxd.dataDrivenPages.pageRow.getValue("FLOOR")
  OutputPath = strOutpath + "\\" + buildingVal + "\\" + floorVal
  arcpy.env.overwriteOutput = True
  arcpy.env.workspace = OutputPath 
  
  #Get DataFrame
  df = arcpy.mapping.ListDataFrames(mxd)[0]
  
  print("Packing " + OutputPath + ".tpk")
  arcpy.CreateMapTilePackage_management(mxdPath, "ONLINE", OutputPath + ".tpk", "PNG8", 24,"","","",df.extent,75,"tpk",0)

del mxd&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp; Thanks!&lt;/P&gt;</description>
    <pubDate>Mon, 25 Oct 2021 18:49:45 GMT</pubDate>
    <dc:creator>Andrew-Bowne</dc:creator>
    <dc:date>2021-10-25T18:49:45Z</dc:date>
    <item>
      <title>Create TPK using Data Driven Pages</title>
      <link>https://community.esri.com/t5/arcmap-questions/create-tpk-using-data-driven-pages/m-p/1110977#M3112</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I am trying to use Data Driven Pages to create Tile packages (TPK) instead of outputting to a PDF or JPG.&amp;nbsp; What I am finding that as I iterate through the pages, the TPK's don't honor the definition query set by the Data Driven Page.&amp;nbsp; In my use case, I am iterating through every floor of a building and trying to write out a TPK (instead of PDF) for every floor.&lt;/P&gt;&lt;P&gt;Is this possible or can you only export to an image?&lt;/P&gt;&lt;P&gt;Here is my Python Script:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os, argparse
parser = argparse.ArgumentParser(description='Export TPK')
parser.add_argument('-inMXD', help='input map document setup for DDP', required=True)
parser.add_argument('-outFolder', help='output folder name where TPKs will be written', required=True)
args = parser.parse_args()

strOutpath = args.outFolder
mxdPath = args.inMXD


#Test if inMXD exists
if os.path.isfile(mxdPath) and os.access(mxdPath, os.R_OK):
  print "input MXD found ( " + mxdPath + ")"
else:
  print "Can NOT find input MXD: " + mxdPath
  exit()

#Test if outFolder exists
if os.path.exists(strOutpath) and os.access(strOutpath, os.W_OK):
  print "Output folder found (" + strOutpath + ")"
else:
  print "Can NOT find output DDP folder:" + strOutpath
  exit()

mxd = arcpy.mapping.MapDocument(mxdPath)

for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
  mxd.dataDrivenPages.currentPageID = pageNum
  pageorder = mxd.dataDrivenPages.pageRow.FloorID
  #Building Value
  buildingVal = mxd.dataDrivenPages.pageRow.getValue("BUILDINGNAME")
  #Floor Value
  floorVal = mxd.dataDrivenPages.pageRow.getValue("FLOOR")
  OutputPath = strOutpath + "\\" + buildingVal + "\\" + floorVal
  arcpy.env.overwriteOutput = True
  arcpy.env.workspace = OutputPath 
  
  #Get DataFrame
  df = arcpy.mapping.ListDataFrames(mxd)[0]
  
  print("Packing " + OutputPath + ".tpk")
  arcpy.CreateMapTilePackage_management(mxdPath, "ONLINE", OutputPath + ".tpk", "PNG8", 24,"","","",df.extent,75,"tpk",0)

del mxd&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp; Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 18:49:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/create-tpk-using-data-driven-pages/m-p/1110977#M3112</guid>
      <dc:creator>Andrew-Bowne</dc:creator>
      <dc:date>2021-10-25T18:49:45Z</dc:date>
    </item>
  </channel>
</rss>

