Influence parameter in Python toolbox

3441
3
11-21-2014 03:18 AM
TomGeo
by
Occasional Contributor III

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

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!
Tags (1)
0 Kudos
3 Replies
DallasShearer
Occasional Contributor

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

0 Kudos
TomGeo
by
Occasional Contributor III

Thanks Dallas,

the stupid thing still comes back saying: File "<string>", line 174, in updateParameters TypeError: 'NoneType' object is not callable

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!
0 Kudos
TomGeo
by
Occasional Contributor III

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.

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!