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',
name='inPolygon',
datatype="GPFeatureRecordSetLayer",
parameterType="Required",
direction="Input")
#replace with a valid template
prmInPolygon.value = r"C:\\template.lyr"
params.append(prmInPolygon)
prmDebug1 = arcpy.Parameter(
displayName="Debug 1",
name="debug1",
datatype="GPString",
parameterType="Optional",
direction="Input")
params.append(prmDebug1)
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
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
return
if parameters[0].altered
, as shown in the sample?