0

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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Dec 20, 2016 at 15:09
3
  • I'm not sure, but one thing I see is that you're allowing overwrite outputs before setting your workspace, is this keeping your outputs from being written due to duplicate files? Commented Dec 20, 2016 at 16:10
  • Per the doc, the first CONVERT is not relevant when using SDE data. Use "CONVERT_ARCSDE". Also, try making lpk a full path using os.path.join (workspace,lpkName.lpk) desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/… Commented Dec 21, 2016 at 14:07
  • So i made the changes you guys suggested but still received the same error. However, I did manage to get it to work simply by combining tag1 and tag2 as a single string. Below is my final code for reference. Commented Jan 3, 2017 at 18:02

1 Answer 1

0

Working code:

import arcpy
import os
arcpy.env.workspace = "D:/Data/"
workspace = arcpy.env.workspace
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
print "environments set"
lpkName = "layerPackage"
lpk = os.path.join(workspace+lpkName+".lpk")
summary = "A summary"
tags = "tag1, tag2"
print "layer package variables defined"
dataFrame = arcpy.mapping.ListDataFrames(mxd, "*")[0]
layers = arcpy.mapping.ListLayers(mxd, "", dataFrame)
for lyr in layers:
 try:
 if lyr.name == "Layer_I_Want":
 print "converting Layer_I_Want to lpk"
 arcpy.PackageLayer_management(lyr, lpk, "PRESERVE", "CONVERT_ARCSDE", 
 "#", "ALL", "ALL", "CURRENT", "#", summary, tags)
 print "lpk created"
except Exception as e: print(e)
mxd.save()
answered Jan 3, 2017 at 18:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.