Python script is failing. It's supposed to make a selection from a lyer based on attributes value and then select intersecting features of that selection and then make a copy of the selection as a new featureclass. I'm getting the error messages at the end but nothing in between and I can't figure out why. I got it working and then added some documentation and then it began failing again. I've tried running it from PythonWin and as a script tool in ArcMap and ultimately prefer to run it in the latter.

# this script selects digitized streets as well as the streets
# they intersect with from outdated centerline files and exports
# to a new featureclass to be merged with up to date centerline file

import arcpy
arcpy.env.overwriteoutput = True

    # Enter parameters and run tool
    inPath = arcpy.GetParameterAsText(0)
    outPath = arcpy.GetParameterAsText(1)
    inPathFL = arcpy.MakeFeatureLayer_management(inPath, "inPathFL")
    arcpy.SelectLayerByAttribute_management(inPathFL, "NEW_SELECTION", ' "Link_ID" <= 10000')
    arcpy.AddMessage("selecting features with link ID less than 10,000")
    arcpy.SelectLayerBylocation_management(inPathFL, "INTERSECT", inPathFL, "10 Feet", "ADD_TO_SELECTION")
    arcpy.AddMessage("selecting layers by location that intersect with currently selected features")
    arcpy.CopyFeatures_management(inPathFL, outPathFL)
    arcpy.AddMessage("copying features")

    # report a success message
    arcpy.AddMessage("Created source streets feature class!")

    # get error messages
    arcpy.AddError("Could not complete the export for the intended selection")

    print "Create source streets failed"

And here is the error message:

Executing: CreateSourceStreets CO_005_2012_Merge C:\RS_Data\Common\MapClips\CO_SF_2015Q2.gdb\CO_SF_2012_Source
Start Time: Tue Dec 08 15:38:11 2015
    Running script CreateSourceStreets...
    selecting features with link ID less than 10,000
    Could not complete the export for the intended selection
    Executing: SelectLayerByAttribute inPathFL NEW_SELECTION " "Link_ID" <= 10000"
    Start Time: Tue Dec 08 15:38:11 2015
    Succeeded at Tue Dec 08 15:38:11 2015 (Elapsed Time: 0.05 seconds)
    Completed script CreateSourceStreets...
    Failed to execute (CreateSourceStreets).
    Failed at Tue Dec 08 15:38:11 2015 (Elapsed Time: 0.76 seconds)

closed as off-topic by PolyGeo Dec 9 '15 at 0:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    This will be easy to debug if you re-test the same code without the try/except functions that are masking the errors that Python and ArcPy provide. – PolyGeo Dec 8 '15 at 23:42

Getting rid of try and except gave me what i needed. SelcetBylocation needed to be changed to SelectByLocation (needed uppercase L).


try the following on your SelectLayerByAttribute_management line arcpy.SelectLayerByAttribute_management(inPathFL, "NEW_SELECTION", """ "Link_ID" <= 10000""")

The """ triple double quotes allow you to pass the Where Clause syntax properly.

  • Nope. Stil getting a message after select by attributes – geoJshaun Dec 8 '15 at 23:42
  • I edited the answer @Shaun, it was supposed to be a triple double quote, not single quote. If this doesn't work I will test your whole code. – yanes Dec 9 '15 at 0:15

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