AnsweredAssumed Answered

Error returned after cursor searching layers from a map

Question asked by BrokenLegMike on Mar 29, 2012
Latest reply on Mar 29, 2012 by BrokenLegMike
Hey everyone,

I want to do this:

  1. Add a feature class as a layer to a map using python

  2. Do a select by location between the added layer and an existing layer in the map

  3. Do a cursor search through the records returned from the select by location and print some values from some fields

From my code below, everything works right up until the select by location. I get the following error:

Traceback (most recent call last):
  File "Z:\ESRI\Python\Test Scripts\", line 60, in <module>
    rows = arcpy.SearchCursor(arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", "polygontest"))
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\", line 820, in SearchCursor
    return gp.searchCursor(*args)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\", line 357, in searchCursor
IOError: "GPL0" does not exist

I was thinking that when I filter down to the "WELLS" layer, then I should have no problem doing the select. I don't need to convert these to feature layers, because they already are layers in a map. I'm not sure what is causing this error.

import arcpy from arcpy import env  env.workspace = r"Z:\Test.gdb"  env.overwriteOutput = True  mxd = arcpy.mapping.MapDocument(r"Z:\Test.mxd")  for df in arcpy.mapping.ListDataFrames(mxd, "*"):      # Add a feature class as a layer from the workspace environment. This works.     addLayer = arcpy.mapping.Layer("polygontest")     arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")      for lyr in arcpy.mapping.ListLayers(mxd, "", df):           # Filter out the layer I want to use in my select by location statement. This works and can print out the datasetName.          if == "WELLS":               print lyr.datasetName               # Select by location any features in the "WELLS" layer that intersect "polygontest" layer. This is where the crash happens.               rows = arcpy.SearchCursor(arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", "polygontest"))                # Search through the records returned from the select by location statement.               for row in rows:                   print str(row.OBJECTID) + " = " + str(row.STATUS)