Traceback (most recent call last):
File "Z:\ESRI\Python\Test Scripts\test.py", line 60, in <module>
rows = arcpy.SearchCursor(arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", "polygontest"))
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 820, in SearchCursor
return gp.searchCursor(*args)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 357, in searchCursor
self._gp.SearchCursor(*gp_fixargs(args)))
IOError: "GPL0" does not exist
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 lyr.name == "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)
Solved! Go to Solution.
arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", "polygontest") rows = arcpy.SearchCursor(lyr)
arcpy.MakeFeatureLayer_management("polygontest", "ply") arcpy.MakeFeatureLayer_management("WELLS", "wells") rows = arcpy.SearchCursor(arcpy.SelectLayerByLocation_management("wells", "INTERSECT", "ply")) for row in rows: print str(row.OBJECTID) + " = " + str(row.STATUS)
arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", "polygontest") rows = arcpy.SearchCursor(lyr)