I currently have a Python 2.7 script that takes a hard-coded select by attribute from ArcMap 10.3.

arcpy.SelectLayerByAttribute_management("SoilLandscapePolygons_Layer", "NEW_SELECTION", "POLY_ID = 25984)

that then copies this polygon and its related tables into a new FGDB. What I want to do, is to have the user select a polygon and then have this polygon copied ... so that I can continue working on it in my script. I'm not doing any editing what so ever but I need this one polygon to begin working through the various relationship tables to create a summary for the selected polygon.

  • Look into using a Feature Set - there a few Q&As here about them
    – PolyGeo
    Feb 28, 2019 at 22:23
  • 2
    If you have a selection in ArcMap then only that selection is used by a geoprocessing tool, you should be able to comment out the line with SelectLayerByAttribute and export only the selected polygon. This is not true for Catalog where a selection must be made within the script. Beware though, if the layer doesn't have a selection when it is passed to your script then all polygons in the layer will be processed, there is no Layer.HasSelection to help decide if the layer has a selection before proceeding.. Feb 28, 2019 at 22:46
  • Gents - I have yet to see how to set up a feature set as part of a tool or as part of an addin. Any suggestions. Also, I agree that once there is a selected polygon, I just can't seem to figure out how to pass it to the script. Feb 28, 2019 at 23:21
  • 1
    @MichaelStimson There's if arcpy.Describe (lyr).FIDSet: which will return True or False depending on if there's a selection on the layer. Feb 28, 2019 at 23:26
  • 1
    The fastest and simplest so far is layer.getSelectionSet (). Will return None or tuple of selected OIDs.
    – FelixIP
    Mar 1, 2019 at 0:54

1 Answer 1


Working in the ArcMap environment you simply need to pass a string of the layer name into your copy code. Thus if the selection is manually done instead of with your SelectLayerByAttribute_management just skip this line of code and proceed with your Copy Features.

If you want to check for a selection first you can use FIDSet.

if arcpy.Describe ("SoilLandscapePolygons_Layer").FIDSet:
    ###copy features
    print "no selection"
  • this is the error that I got "AttributeError: DescribeData: Method FIDSet does not exist" Mar 1, 2019 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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