AnsweredAssumed Answered

error creating list with append

Question asked by cynthiak on Feb 21, 2017
Latest reply on Feb 21, 2017 by cynthiak

This should be so easy.  I have a script that runs perfectly from the ArcMap python window, but errors out when run from a script tool or IDLE.  It errors on the AddJoin because it says that finalParc does not exist.  I believe it is because the Intersect_analysis is not running correctly.  I don't know if the inFeatures list is not being created correctly or it is having trouble with the names in the list.  The point of my script is to determine if the main layer - parcBuff - is overlapped by any of the other layers.  If it is, then run an intersect_analysis on those overlapping layers to create one final layer - finalParc - that has the attributes of all those layers in it.


Here is part of the code that should accomplish that...and I need it to run through a Tool.....



#Create a cursor to go through all the layers. If layer does not intersect, apply N/A, otherwise, intersect....
#Make Layer Views......
arcpy.MakeFeatureLayer_management(parcBuff, "parcBuff")
arcpy.MakeFeatureLayer_management(zoning, "zoning")
arcpy.MakeFeatureLayer_management(fldplain, "fldplain")
arcpy.MakeFeatureLayer_management(compplan, "compplan")
arcpy.MakeFeatureLayer_management(fire, "fire")
arcpy.MakeFeatureLayer_management(school, "school")
arcpy.MakeFeatureLayer_management(irrigate, "irrigate")
arcpy.MakeFeatureLayer_management(ressoils, "ressoils")
arcpy.MakeFeatureLayer_management(soils, "soils")
arcpy.MakeFeatureLayer_management(uga, "uga")

#Cursor layers......
layerList = {"zoning", "fldplain", "compplan", "fire", "school", "irrigate", "ressoils", "soils", "uga"}
inFeatures = ["parcBuff"]
for theLayer in layerList:
     arcpy.SelectLayerByLocation_management("parcBuff", "INTERSECT", theLayer)
     selCount = int(arcpy.GetCount_management("parcBuff").getOutput(0))
     print selCount
     if (selCount != 0):
         inFeatures.append("%s" % theLayer)


#inFeatures = ["parcBuff", "zoning", "fldplain", "compplan", "uga", "soils", "ressoils", "irrigate", "school", "fire"]
arcpy.Intersect_analysis(inFeatures, finalParc, "NO_FID", "", "")


#Join the Party table to the parcel with all the information from the layers.....
#Set the variables....
layerName = "finalParc"
joinField = "ASSESSOR_N"
arcpy.AddJoin_management(layerName, joinField, party, joinField) 


Hopefully, this is enough information.  Thank you for your help!