I am trying to get the count of features in a GPFeatureRecordSetLayer parameter before executing the tool. By using the arcpy.GetCount_management tool I am getting 0 all the times (see code below). I have also tried to use the JSON property of the input FeatureSet but still with no success. Running the arcpy.GetCount_management tool in Execute method of the tool gives me the correct number but I need it before that so I can use it for validation. Is there a way to get the features count of a GPFeatureRecordSetLayer parameter and use it to add an error message to the parameter if the count is greater than 1?

import arcpy

class Toolbox(object):

    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Toolbox"
        self.alias = ""

        # List of tool classes associated with this toolbox
        self.tools = [Tool]

class Tool(object):

    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "InteractiveInput"
        self.description = "Test Interactive Input"
        self.canRunInBackground = False

    def getParameterInfo(self):
        params = []

        prmInPolygon = arcpy.Parameter(
            displayName='Interactive Polygon',
        #replace with a valid template
        prmInPolygon.value = r"C:\\template.lyr"

        prmDebug1 = arcpy.Parameter(
            displayName="Debug 1",

        return params

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        result = arcpy.GetCount_management(parameters[0].valueAsText)
        count = int(result.getOutput(0))
        parameters[1].value = count


    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""

    def execute(self, parameters, messages):
        """The source code of the tool."""
  • 1
    Did you try doing the validation only if parameters[0].altered, as shown in the sample? Aug 15, 2016 at 13:56
  • I've changed the debug value to the following line of code: parameters[1].value = parameters[0].altered and I get 1 (TRUE) all the time (it is 1 when I start the tool). But this will still not help me as I want to count the number of features given as input.
    – M. Bogdan
    Aug 15, 2016 at 15:48
  • 1
    If this will work, your biggest problem is going to be getting an accurate count. featureSets use the edit framework. The last feature created is always SELECTED. GetCount HONORS selections. So if a user has created 10 features, the last feature will have a selection and get count will return "1". I'm almost positive you cant clear a selection from validation, and since the feature set is inmemory, you cant goto its source and count all the features. I dont know if you'd have luck asking your users to clear a selection after they made some features.
    – KHibma
    Aug 15, 2016 at 16:14
  • 1
    That said, you could, inside your tool (on execute) simply select feature = 1 and always take the first value they've created if they refuse to follow your design rules :)
    – KHibma
    Aug 15, 2016 at 16:21

1 Answer 1


It looks like the GetCount tool doesn’t work because the updateParameters is not triggered. When another parameter is changed, and the updateParameters function is called, the GetCount returns the correct value (it doesn't take into consideration any selected features). This means that no matter what are the edits for a GPFeatureRecordSetLayer parameter, the updateParameters is not called (even if you press Editor>Save edits).

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.