Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

What is the fastest/cleanest way to get a collection of rows that are selected in a certain layer? For some background, I am trying to hide selected features in a specified layer.

Is there a way to get the selected rows by using a layer object which is provided by a script parameter?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can use the following to grab the OID of selected features within a layer.

FIDSet = arcpy.Describe(layer).FIDset
records = [int(FID) for FID in FIDSet.split(";")] if FIDSet else []

This way, you can make a selection, grab the OIDs, and clear selection.

arcpy.SelectLayerByAttribute_management(layer, "CLEAR_SELECTION")

It should occur quickly, so the selection may not be visible.

share|improve this answer
This works. Just to note, the code will throw an exception because the string given by arcpy.Describe(layer).FIDset is a series of id codes. You want: map(int,arcpy.Describe("test").FIDset.split("; ")) – Eyrofire Mar 4 '14 at 18:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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