-1

Its strange that the script would start and work on some data, but then fails more than half way through. Here is the error message and relevant script (error line 229 in bold)

line 229, Select_and_Calc(CoverQuery,CoverType,CoverCode,FRST_Code) Error Info: : ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute).

  def Select_and_Calc(Query, Type, Code, ReClassCode):
    arcpy.SelectLayerByAttribute_management("inLayer","NEW_SELECTION",Query)
    CountSel = arcpy.GetCount_management("inLayer").getOutput(0)
    arcpy.AddMessage("\t"+str(CountSel)+"\t("+str(Code)+")\t"+\
    string.upper(Type))
    if int(CountSel) > 0:
      arcpy.CalculateField_management("inLayer","COVER",'"'+Type+'"')
      arcpy.CalculateField_management("inLayer","CT",Code)
      arcpy.CalculateField_management("inLayer","REG_CT",ReClassCode)
      CounterExpression = '[COUNTER] + 1'
      arcpy.CalculateField_management("inLayer","COUNTER",CounterExpression)

  CoverType = "rock"
  CoverCode = "28"
  FRST_Code = "31"
  CoverQuery = '"NON_FRST" = 30 AND "NON_FRST_SPP_OS" = 0 AND "NON_FRST_TCC" = 0'
  Select_and_Calc(CoverQuery,CoverType,CoverCode,FRST_Code)
1

To debug this I would suggest changing:

 def Select_and_Calc(Query, Type, Code, ReClassCode):
    arcpy.SelectLayerByAttribute_management("inLayer","NEW_SELECTION",Query)

to:

 def Select_and_Calc(Query, Type, Code, ReClassCode):
    print Query
    arcpy.SelectLayerByAttribute_management("inLayer","NEW_SELECTION",Query)

That way the first time it hits ERROR 000358: Invalid expression you will know what the expression it tried to use was.

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.