I'm trying to create a layer package from a feature layer (whose data source is a feature class) using arcpy. However, I keep getting the following error:
Object: Error in executing tool
Here's the code I'm using:
import arcpy
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "D:/Data/"
mxd = arcpy.mapping.MapDocument("CURRENT")
print "environments set"
lpk = "layerPackage.lpk"
summary = "A summary"
tags = "tag1", "tag2"
print "layer package variables defined"
dataFrame = arcpy.mapping.ListDataFrames(mxd, "*")[0]
layers = arcpy.mapping.ListLayers(mxd, "", dataFrame)
print layers
for lyr in layers:
try:
if lyr.name == "Layer_I_Want":
print "converting Layer_I_Want to lpk"
arcpy.PackageLayer_management(lyr, lpk, "CONVERT", "PRESERVE_ARCSDE",
"#", "ALL", "ALL", "CURRENT", "#", summary, tags)
print "lpk created"
except Exception as e: print(e)
mxd.save()
How do I fix it?
I've tried different combinations of "CONVERT"/"PRESERVE" but still get the same error.