i've been searching arround all the answers in the questions of Error 358 and beyond, but i doesn't fix my problems, i tried every post and so on the problems stills there.

I make two options in my code, one make the error 358 appears, and the other option make the error 999999 with invalid SQL. If i put the code "by hand" in the SelectLayerByAttribute_management it works, but i need to be an input by the user. The query its the same by hand and by the script and i dont know how to make it run.

Sorry for the english, not my maternal lenguaje.

The code is:

Zona_trab=raw_input("Introduzca la ruta de la GDB/carpeta sobre el que se trabajara") arcpy.env.workspace = Zona_trab CapaObj=raw_input("Introduzca el nombre de la capa de tuberias") CapaArq=raw_input("Introduzca el nombre de la capa de arquetas") puntos = raw_input("Introduzca las arquetas con datos de permalogs, separadas por espacios: ") query = '' first = True for punto in puntos.split(): if not first: query = query + 'OR ' query = query + '\\"FID\\" = ' + punto + ' ' first = False query = '" '+query+' "' TempCarp="C:\\Trabajo Carto\\TempPrograma" arcpy.MakeFeatureLayer_management(CapaObj,"capa tuberias") arcpy.MakeFeatureLayer_management(CapaArq, "capa puntos") arcpy.SelectLayerByAttribute_management("capa puntos","NEW_SELECTION", query) arcpy.SelectLayerByLocation_management("capa tuberias", "WITHIN_A_DISTANCE","capa puntos","1 Meters", "NEW_SELECTION") arcpy.FeatureClassToFeatureClass_conversion("capa tuberias",TempCarp,"Final.shp","","","")

The second option, wich give me a error 999999 its deleting the arcpy.SelectLayerByAttribute_management("capa puntos","NEW_SELECTION", query) and making the selection in the arcpy.MakeFeatureLayer_management(CapaArq, "capa puntos", query) this makes the error goes in arcpy.SelectLayerByLocation_management("capa tuberias", "WITHIN_A_DISTANCE","capa puntos","1 Meters", "NEW_SELECTION").

I hope get some response because i'm stuck in there :(

  • 1
    Welcome to GIS@SE .. What database are you using? Please modify your question to include the Database, version and extensions .. Jan 5, 2015 at 11:06

2 Answers 2


To workaround your 999999 error I think something very easy and useful to try will be:

  1. Use arcpy.Select_analysis in place of MakeFeatureLayer + SelectByAttribute + FeatureClassToFeatureClass
  2. Then just MakeFeatureLayer + SelectByLocation + FeatureClassToFeatureClass on the result of 1

It should simplify the Geoprocessing involved and reduce the amount of memory needed.

  • Still the same error, idk if i must ad "" to the numbers, because in other responses some people uses, and other dont ERROR 000358: Invalid expression "\"FID\" = 3 OR \"FID\" = 5 OR \"FID\" = 6 OR \"FID\" = 8 " Failed to execute (Select). And also thanks ^^
    – Gsanez
    Jan 5, 2015 at 11:05
  • @Gsanez Try this instead '''"FID" = 3 OR "FID" = 5 OR "FID" = 6 OR "FID" = 8'''. If it does not just work then I think you should research/ask about the 000358 error separately from the 999999 error. It's the latter error that my answer was targeting.
    – PolyGeo
    Jan 5, 2015 at 11:07

instead of your loop, you could use the "in" operator

puntos = raw_input("Introduzca las arquetas con datos de permalogs, separadas por comas: ")#separate with comas
query = """ "FID" in (""" + puntos + """)"""

Note that you don't need the \ in your code

' \\"FID\\" ' gives \"FID\"

you just need ' "FID" ' or """ "FID" """ or " \"FID\" "

  • Thx a lot, with a combo of the two responses it now works. We solve the problem with the 358 whit your "in" and the 999999 wiht the select from the previous response ^^
    – Gsanez
    Jan 5, 2015 at 11:24

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.