[GIS] AttributeError: DescribeData: Method FIDSet does not exist error

arcgis-10.2arcpypython-addin

I am writing an add-in that in one step requires to find all layers that have selections. To achieve that I am using FIDSet property of Describe object. Unfortunately, I get an error: "AttributeError: DescribeData: Method FIDSet does not exist" (why "method" anyway?). While I perform test like this, in Python window in ArcMap:

desc = arcpy.Describe("O_PODST")
desc.FIDSet()

Everything works fine, but while using my add-in I get this error.
How to make it work?
Here is my code:

class ShowParcLU(object):
    """Implementation for Okienko_addin.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False

    def onClick(self):
        mxd = arcpy.mapping.MapDocument("CURRENT")

        if arcpy.mapping.ListTableViews(mxd, "PARC_LU"):
            layers_with_selections = []

            for i in arcpy.mapping.ListLayers(mxd):
                if len([int(fid) for fid in arcpy.Describe(i).FIDSet.split(";") if fid != '']) > 0:
                    layers_with_selections.append(i)

Best Answer

FIDSet is a Describe property of a feature layer. dataSource will return the full path to a layer's data source. In your code, you want to reference the layer, not its data source, so remove dataSource.

if len([int(fid) for fid in arcpy.Describe(i).FIDSet.split(";") if fid != '']) > 0:

FYI, cleaner code to get what you're after (checking for selection):

if arcpy.Describe(i).FIDSet:
Related Question