Create Map Tile Package - Cannot run python script

2111
3
03-09-2016 10:54 AM
VitorFranca
New Contributor II

Hi folks,

Using ArcGIS version is 10.2.2, I am trying to use arcpy.CreateMapTilePackage_management() GP tool in the script bellow to automate production of a large quantity of map packages to be used in handheld devices. I can create packages using the menu - File > Share As > Tile Package, but can not put the script to work, neither using ArcMap Python window or IDLE. I get the same error message:

Runtime error

Traceback (most recent call last):

  File "<string>", line 14, in <module>

  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 7170, in CreateMapTilePackage

    raise e

RuntimeError: Object: Error in executing tool

Here is my script:

import arcpy, os

import arcpy.mapping

mxd = arcpy.mapping.MapDocument('CURRENT')

df = arcpy.mapping.ListDataFrames(mxd, "MSR") [0]

# Cursor

for row in arcpy.SearchCursor("T_LM_SETORES"):

  df.extent = row.SHAPE.extent # ajusta a extensao do dataframe a extensao do setor

  df.scale = df.scale * 1.1 # ajusta a escala para dar uma margem maior ao setor no mapa

  arcpy.RefreshActiveView()

  geocodigo =  row.getValue("cd_geocodigo")

  mxd.save()

  print("Saving map tile package for sector " + geocodigo)

  arcpy.CreateMapTilePackage_management( mxd, "ONLINE", r"G:\\BaseTerritorial\\Atendimentos\\2PP_CensoAgro\\MapTilePackages\\" + geocodigo + ".tpk", "JPEG", "19", "#", "Test map package generation", "tag1, tag2")

0 Kudos
3 Replies
DanPatterson_Retired
MVP Esteemed Contributor

can you format your code  Code Formatting... the basics++

... and use single \ if you are using raw notation not double... it gets messy

>>> x = r"G:\\BaseTerritorial\\Atendimentos\\2PP_CensoAgro\\MapTilePackages\\"

>>> x

'G:\\\\BaseTerritorial\\\\Atendimentos\\\\2PP_CensoAgro\\\\MapTilePackages\\\\'

VitorFranca
New Contributor II

import arcpy, os

import arcpy.mapping

mxd = arcpy.mapping.MapDocument('CURRENT')

df = arcpy.mapping.ListDataFrames(mxd,"MSR") [0]

# Cursor

for row in arcpy.SearchCursor("T_LM_SETORES"):

  df.extent = row.SHAPE.extent # ajusta a extensao do dataframe a extensao do setor

  df.scale = df.scale * 1.1 # ajusta a escala para dar uma margem maior ao setor no mapa

  arcpy.RefreshActiveView()

  geocodigo =  row.getValue("cd_geocodigo")

  mxd.save()

  print("Saving map tile package for sector " + geocodigo)

  arcpy.CreateMapTilePackage_management( mxd, "ONLINE", r"G:\BaseTerritorial\Atendimentos\2PP_CensoAgro\MapTilePackages\" + geocodigo + ".tpk", "JPEG", "19", "#", "Test map package generation", "tag1, tag2")

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

I would have expected a different error message since your file path ends in a backslash

>>> geocodigo = "x"

>>> x = r"G:\BaseTerritorial\Atendimentos\2PP_CensoAgro\MapTilePackages\" + geocodigo + ".tpk"

Traceback (  File "<interactive input>", line 1

    x = r"G:\BaseTerritorial\Atendimentos\2PP_CensoAgro\MapTilePackages\" + geocodigo + ".tpk"

                                                                                             ^

SyntaxError: EOL while scanning string literal

>>> x = r"G:\BaseTerritorial\Atendimentos\2PP_CensoAgro\MapTilePackages" + "\\" + geocodigo + ".tpk"

>>>