0

My problem is that this tool works perfectly in IDLE or PyScripter programs, but if I use in the script in ArcGIS desktop this problem occurs: arcgisscripting.ExecuteError:ERROR 000582...

Why does it not execute in ArcGIS script but works in the programs?

The tool SelectLayerByAttribute management is inside the arcpy.da.UpdateCursor

This is my code:

import arcpy
import datetime
arcpy.env.overwriteOutput = True

territory= arcpy.GetParameterAsText(0)
path= arcpy.GetParameterAsText(1)
territory_lyr=  path+ "territorios_lyr"

arcpy.MakeFeatureLayer_management(territory,territory_lyr)
fields= ("FID", "avg_mindis", "I_conc", "Max_lenght","TamanoTerr")
with arcpy.da.UpdateCursor(territory,  fields) as cursor:
    for row in cursor:
        currentID= row[0]
        where= "FID="+str(currentID)
        arcpy.SelectLayerByAttribute_management(territory_lyr, "NEW_SELECTION",where)

Image ArcToolbox scrpit of Arcgis Desktop  and I am print the error in the line select by atribute

  • Try to use some simple print statements to see if you can identify which step is causing the error. I'd start by printing the territory_lyr variable to make sure the path is what you are expecting. – Jason Feb 19 '14 at 18:55
  • thanks but I have already done, the route and variables are fine. because the code works in other programs – Rafael Vargas Feb 19 '14 at 18:59
  • Are you running this as a custom python tool or copy paste in the python editor? It won't work for the latter since your variables (as currently defined) have to come from a tool. – Paul Feb 19 '14 at 20:40
  • Thanks Pual, but i use the code python in a script of ArcToolbox, so, my variables using this scrpit coming from the user in this case i get out the error. in the other case, if i use the python editor o PyScripter program this code worked successful – Rafael Vargas Feb 19 '14 at 21:46
1

At this point, the problem with your where clause is that it will be interpreted as (assuming FID = 1 what you should have is "FID" = 1 (or [FID] with personnal geodatabase), therefore the python command need to be

' "FID" = ' + str(row[0])

Remark : It is a bit strange to create a layer inside a cursor, especially with FID's which are ranked suites of integers and relying on the same feature class, but you probably have good reasons in the remaining of your code. Maybe if you give more details about the rest of your code (in another question), a better solution could be provided. For instance you could immediately work with the geometry from your cursor, or create your layer in a loop like this :

for i in range(int(arcpy.GetCount_management(territory_lyr).getOutput(0)) ):
    arcpy.SelectLayerByAttribute_management(territory_lyr, "NEW_SELECTION",'"FID" =' + str(i) ) #maybe i + 1 depending of your input type
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.