Is it possible to filter the available feature layers for a parameter based on the attribute table the same way we can filter based on the shape type:
# Define the sample paramter
Samples = arcpy.Parameter(
displayName="SamplePoints",
name="SamplePoints",
datatype="GPFeatureLayer",
parameterType="Required",
direction="Input")
# Require the sample to be Points
Samples.filter.list = ["Point"]
# Reqiore the feature class of the layer to have the Float 'value' and Date 'SampleDate'
# ???
Here i want only to be able to select a feature layer for a feature class that have the attribute "value" and "SampleData"
Solved! Go to Solution.
I don't think there's a way to do it as an in-built filter, but you use tool validation to check.
Try something like this? (Not super-tested but it should work)
def updateMessages(self, params):
Samples = params[0]
if Samples.value:
field = {f.name:f.type for f in arcpy.ListFields(Samples.value)}
valueFieldType = fields.get("value", None)
SampDateFieldType = fields.get("SampleDate", None)
if not (valueFieldType and SampDateFieldType):
Samples.setErrorMessage('Feature Class must have a field named "value"'
'and a field named "SampleDate')
if valueFieldType != "Single":
Samples.setErrorMessage('"value" field must be a Float field')
if SampDateFieldType != "Date":
Samples.setErrorMessage('"SampleDate" field must be a Date field')
I don't think there's a way to do it as an in-built filter, but you use tool validation to check.
Try something like this? (Not super-tested but it should work)
def updateMessages(self, params):
Samples = params[0]
if Samples.value:
field = {f.name:f.type for f in arcpy.ListFields(Samples.value)}
valueFieldType = fields.get("value", None)
SampDateFieldType = fields.get("SampleDate", None)
if not (valueFieldType and SampDateFieldType):
Samples.setErrorMessage('Feature Class must have a field named "value"'
'and a field named "SampleDate')
if valueFieldType != "Single":
Samples.setErrorMessage('"value" field must be a Float field')
if SampDateFieldType != "Date":
Samples.setErrorMessage('"SampleDate" field must be a Date field')
Hi @AlfredBaldenweck
Thank you for you solution, I learn a lot from it.
I was hoping for a way to filter the options in the drop down, but this works as well Thanks again.
def updateMessages(self, params):
samples = params[0]
if samples.value:
fields = {f.name:f.type for f in arcpy.ListFields(samples.value)}
valueFieldType = fields.get("value")
SampDateFieldType = fields.get("SampleDate")
if valueFieldType is None or SampDateFieldType is None:
samples.setErrorMessage('Feature Class must have a field named "value"' 'and a field named "SampleDate')
if valueFieldType != "Double":
samples.setErrorMessage(f'"value" field is of type {valueFieldType} must be a Float field')
if SampDateFieldType != "Date":
samples.setErrorMessage(f'"SampleDate" field is of type {SampDateFieldType} must be a Date field')
Glad it worked. One thing to watch out for is that you check to see if the field type is "Double", but you your error message says the field type must be "Float", which is actually "Single". You should either change what you're checking for or change your error message.