I have the issue that I want to set value of a parameter from within the updateParameters function in a Python toolbox.
The parameter is defined like this:
def getParameterInfo(self):
in_fc_mark = arcpy.Parameter(
displayName="Field Data (calculation year)",
name="pln_classes",
datatype="String",
parameterType="Required",
direction="Input")
# Define calculation year
int_today = datetime.datetime.today().year
in_int_year = arcpy.Parameter(
displayName="Calculation Year",
name="str_years",
datatype="GPLong",
parameterType="Required",
direction="Input")
in_int_year.filter.type = "Range"
in_int_year.filter.list = [1980, int_today+1]
parameters = [in_fc_mark,
in_int_year]
return parameters
and I would like to set the value for it this way:
def updateParameters(self, parameters):
if parameters[0].altered:
str_file = datetime.datetime.strftime(dparser.parse(os.path.basename(parameters[0].valueAsText), fuzzy=True),'%Y%m%d')
if str_file[:4].isdigit():
parameters[1].value(int(str_file[:4]))
return
However, it doesn't work. I can enable parameters of type "GPBoolean" with parameters[1].enabled = True, but setting the value gives me trouble. How can I do this?
Bests, Thomas
maybe try changing the update statement to this.
def updateParameters(self, parameters):
if not parameters[1].altered:
str_file = datetime.datetime.strftime(dparser.parse(os.path.basename(parameters[0].valueAsText), fuzzy=True),'%Y%m%d')
if str_file[:4].isdigit():
arcpy.AddMessage(int(str_file[:4]))
parameters[1].value(int(str_file[:4]))
return
Thanks Dallas,
the stupid thing still comes back saying: File "<string>", line 174, in updateParameters TypeError: 'NoneType' object is not callable
Okay, I just found it... Well, to assign a value you have to say:
parameters[1].value = int(str_file[:4])
So, now it works without any problems.