I am trying to loop thru selected features using the da.SearchCursor statement below. It works when the users selects something. When there are no points or lines selected it returns the whole layer. Should I be using another function?
with arcpy.da.SearchCursor(manhole_layer,"*") as cursor:
for row in cursor:
Solved! Go to Solution.
Before opening the search cursor, could you check to see if any features are selected? If there are selected features, continue to use search cursor; If not, handle exception.
Assuming it is a layer, here's the direction I would go.
I have not tested this. You may have to check for a length like len(desc.FIDSet) > 0
desc = arcpy.Describe(manhole_layer)
if desc.FIDSet:
# Do something with selection
with arcpy.da.SearchCursor(manhole_layer, "*") as cursor:
for row in cursor:
print row
else:
# Handle Exception
print "No features selected."
Before opening the search cursor, could you check to see if any features are selected? If there are selected features, continue to use search cursor; If not, handle exception.
Assuming it is a layer, here's the direction I would go.
I have not tested this. You may have to check for a length like len(desc.FIDSet) > 0
desc = arcpy.Describe(manhole_layer)
if desc.FIDSet:
# Do something with selection
with arcpy.da.SearchCursor(manhole_layer, "*") as cursor:
for row in cursor:
print row
else:
# Handle Exception
print "No features selected."