1

within a Python toolbox in ArcGIS 10.2 I fill a parameter with a list. parameters[0].filter.list = myList It is essentialy a list of strings and will give the user a range of predefined years. Later I check a file name if it holds information of a year. In case there is a year to be extracted from the name I want the value in the list defined for parameters[0] to be selected.

If I use SetParameterAsText() then I will overwrite my list of years, and cut my user short on the possibility to correct the year in case the extracted year is not the one the user is focusing on.

Since the year is anyway already part of the list... is there a way to say parameters[0].SelectValue() or parameters[0].SelectListItem() to get a visual confirmation for the user?

I hope it is understandable what I want to achieve.

  • Please clarify what you are trying to accomplish and how your user is interacting with the list of years (I'm guessing they are choosing a value from the list on the form, an image of the form might help) and how you expect them to get visual confirmation of the file name year? Do you want to select the file name year from the list on the form by default unless the user changes it? – jbosq Nov 20 '14 at 15:16
  • Alright, when the tool is called and the form initiated, the list is created upfront. lst_years = [] int_year = datetime.datetime.today().year for in_year in range(1980, int_year+1): lst_years.append(str(in_year)) As soon as the user specifies a featureclass in the form, the name is analysed if there is a piece in it that can be turned into a datetime object and will be returned as a string. Let's say it's 2000. Then 2000 can be found in the pre-made list ans inside the form it should be selected. If that's not what the user wants, he still should be able to change it. – Thomas Becker Nov 21 '14 at 9:28
2

Once you get the year you should be able to just assign it to parameters[0].value. Also there is an example that may be useful to you here. Look at the first example from the top of the page where it writes param1.value = 'sinuosity'.

  • Nice try, but unfortunately I am getting an error of NoneType object is not callable. Below the way I define the parameter. # 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] – Thomas Becker Nov 21 '14 at 10:42
  • Sorry for the mess with the code but the formating simply does not do what it should do in the comments. – Thomas Becker Nov 21 '14 at 10:45
  • In the end it was all much more easy... than I thought. I simply wanted to assign the value by parameters[1].value(whatSoEver)instead of parameters[1].value = whatSoEver – Thomas Becker Nov 25 '14 at 13:30
1

The problem could be where you are trying to set the value, for a pyt I've had more luck doing this in updateParameters, after the FC gets its value rather than using a filter in the getParameterInfo. With parameters[0] as the FC and parameters[1] as your date value:

def updateParameters(self, parameters):
    if parameters[0].altered
    #set your yearValue according to parameters[0]
    #you'll also either set int_today here or need to pull that in from where you set it
         parameters[1].filter.type = "Range"
         parameters[1].filter.list = [yearValue, int_today+1]

I believe that will give the user the option to select the generated date and no other options from the list, I haven't tried to see what happens when they want to change it. The other options would be to filter by the original list but instead setting the desired value as the default using defaultEnvironmentName but i've never tried doing that in the updateparameters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.