AnsweredAssumed Answered

Influence parameter in Python toolbox

Question asked by TomGeo on Nov 21, 2014
Latest reply on Nov 25, 2014 by TomGeo

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

Outcomes