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?
In this particular situation, we are not using the actual town names. Instead the "town name" is actually an alphanumeric code as a text item. Examples are AR021, HA007, PI063. There are no special characters or spaces in any of the names.
And it is a different town each time- a town that will cause the program to quit on one try will work just fine on another try (and vice versa). Again, no error messages, just stopping.
My coding preference is to NOT use try, except blocks so that I can get a useable error message...others like them, but I prefer to be stopped cold in a line and fix it. But...having said that, there are times that your logic seems to be deleting a layer that you are trying to use again in a makefeature layer? I am not following something. Could be a filename thing or a path thing, I would suggest printing full paths and change the names if necessary.
In an earlier version of the script I used Try blocks, but I have removed them in the current version (unless you see any that I didn't remove?).
I'll investigate the file/path names, but if you see anything in particular that looks suspicious, please let me know.
a visual to code formatting as well Code Formatting... the basics++