Create TPK using Data Driven Pages

10-25-2021 11:49 AM
Labels (1)
Occasional Contributor III

Hi All,

I am trying to use Data Driven Pages to create Tile packages (TPK) instead of outputting to a PDF or JPG.  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.  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.

Is this possible or can you only export to an image?

Here is my Python Script:

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 + ")"
  print "Can NOT find input MXD: " + mxdPath

#Test if outFolder exists
if os.path.exists(strOutpath) and os.access(strOutpath, os.W_OK):
  print "Output folder found (" + strOutpath + ")"
  print "Can NOT find output DDP folder:" + strOutpath

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


0 Kudos
0 Replies