Getting list of selected features in ArcGIS for Desktop using Python code?

Any time you have a selection on a layer a cursor object will only return the selected rows.

for row in arcpy.SearchCursor("name_of_layer_with_selection"):
    print row.field1, row.field2

the Describe function will also return a list. I am not sure if this is faster than the cursor method but I have fond this to be a useful tool. The resulting list is the object id's for the selection set.

import arcpy

aa = arcpy.Describe("someFC")
ss = aa.FIDset
tt = ss.split("; ")
Print tt

[u'1363', u'1364', u'1365', u'1367', u'1369', u'1370']

Tags:

Select

Arcpy