I am working on a Python script that includes a cursor looping process to create KML files for individual towns. For each iteration of the loop, the script creates a feature layer, then exports that feature layer to KML.
The problem is, the script tends to stop working for no apparent reason. After each KML is created from the feature layer, I delete the feature layer so a new one can be created for the next town. The script tends to stop at this point. No error messages, and it doesn't stop at the same town every time I try. Here is the code that manipulates the feature layer:
try:
print "Deleting feature layer..."
arcpy.Delete_management(parcelsProject_Layer)
print "...deleted it"
except:
print "Couldn't delete feature layer!", sys.exc_info()[0]
raise
else:
# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(parcelsProject_shp, parcelsProject_Layer, expression, "", "FID FID VISIBLE NONE;TOWN TOWN VISIBLE NONE;COUNTY COUNTY VISIBLE NONE;GEOCODE GEOCODE VISIBLE NONE;STATE_ID STATE_ID VISIBLE NONE;MAP_BK_LOT MAP_BK_LOT VISIBLE NONE;PARENT PARENT VISIBLE NONE;PROP_LOC PROP_LOC VISIBLE NONE;PROPLOCNUM PROPLOCNUM VISIBLE NONE;TYPE TYPE VISIBLE NONE;FMUPDORG FMUPDORG VISIBLE NONE;FMUPDAT FMUPDAT VISIBLE NONE;FMSRCORG FMSRCORG VISIBLE NONE;Shape_STAr Shape_STAr VISIBLE NONE;Shape_STLe Shape_STLe VISIBLE NONE;Shape Shape VISIBLE NONE;Shape_ST_1 Shape_ST_1 HIDDEN NONE;Shape_ST_2 Shape_ST_2 HIDDEN NONE")
# Process: Layer To KML
gp.AddMessage("Converting town to KML")
arcpy.LayerToKML_conversion(parcelsProject_Layer, parcels, "0", "false", parcelsProject_Layer, "1024", "96", "CLAMPED_TO_GROUND")
--Any suggestions?