tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n "\ + str(sys.exc_type) + ": " + str(sys.exc_value) + "\n" msgs = "ARCPY ERRORS:\n" + arcpy.GetMessages(2) + "\n" print pymsg print msgs
Hi Adam...Here is an example of the code...with some modificationsimport arcpyimport datetimeimport osimport sysimport tracebackarcpy.env.overwriteOutput = Trueterritory= arcpy.GetParameterAsText(0)path= arcpy.GetParameterAsText(1)arcpy.MakeFeatureLayer_management(territory,"territory_lyr")fldFID = arcpy.Describe(territory).OIDFieldNameprint "ID: "+fldFIDfields= (fldFID, "avg_mindis", "I_conc", "Max_lenght","TamanoTerr")try: with arcpy.da.UpdateCursor(territory, fields) as cursor: for row in cursor: currentID = row[0] where = "{0}={1}".format(arcpy.AddFieldDelimiters(territory, fldFID), currentID) print "where: "+where arcpy.SelectLayerByAttribute_management("territory_lyr", "NEW_SELECTION", where) print "Selection ok"except Exception as e: tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n "\ + str(sys.exc_type) + ": " + str(sys.exc_value) + "\n" msgs = "ARCPY ERRORS:\n" + arcpy.GetMessages(2) + "\n" print pymsg print msgsand the error is....[ATTACH=CONFIG]31637[/ATTACH]
territory= arcpy.GetParameterAsText(0) path= arcpy.GetParameterAsText(1) arcpy.MakeFeatureLayer_management(territory,"territory_lyr") fldFID = arcpy.Describe(territory).OIDFieldName print "ID: "+fldFID fields= (fldFID, "avg_mindis", "I_conc", "Max_lenght","TamanoTerr") try: with arcpy.da.UpdateCursor("territory_lyr", fields) as cursor: for row in cursor: currentID = row[0] where = "{0}={1}".format(arcpy.AddFieldDelimiters("territory_lyr", fldFID), currentID) print "where: "+where #instead of making selection, just create a new feature layer using the where clause arcpy.MakeFeatureLayer_management("territory_lyr","territory_lyrSELECT",where) #arcpy.SelectLayerByAttribute_management("territory_lyr", "NEW_SELECTION", where) print "Selection ok"
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.