Re-ordering Value List in Tool Validator

05-12-2021 04:34 PM
Regular Contributor

I had set a parameter in an ArcGIS custom tool to populate a list upon initialization in an ArcGIS Desktop tool. The parameter has the following properties:

  • Data Type = String
  • Required
  • Input
  • Multivalue = Yes
  • Filter = Value List

In the validator, I scripted some logic that builds a list in a certain order and is then passes it into the parameter using the following:

valueList = ['Montreal', 'Toronto', 'Vancouver', 'British Columbia', 'Ontario', 'Quebec']

self.params[4].filter.list = valueList
self.params[4].values = self.params[4].filter.list  

The list above is an example of how my list is constructed, where I wanted all the city names first and then the provinces after. The cities are in alphabetical order and then the provinces are. When I pass the list into the parameter, the parameter honors the order of the list. This in in the Desktop environment.

I am migrating the tool into ArcGIS Pro/Python 3 using the same validator script and as I noted in a previous post that the behavior of multi value parameters have changed slightly. In the Desktop environment, the list would populate in the parameter along with check boxes next to each item so the user can toggle the items that want the tool to run on:


In the Pro environment the parameter will populate the list, but in order for the user to choose the items from the list they want, there is a drop down button above the parameter that pops out the same list in a new menu where they have the option to toggle on or off the items (see highlighted button below). The second image shows the popout list.



Now the issue is, the original list will populate in the order that I have set in the validator, however the popout list will only populate in alphabetical order. This is onerous for my users because the list I actually use is quite large and we want to have some of the more important items in the list at the top for ease of access and to prevent the users from scrolling through the list for these items when they are set in alphabetical order.

Is there any way to change how the popout list orders the items from the list?



5 Replies
MVP Regular Contributor

Mike, can you provide a bit more of your script? I can't reproduce (using Pro 2.6.1).  With the following script (not using a validator, but just setting the parameters) I get your desired behaviour:



class Tool(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Tool"
        self.description = ""
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        param0 = arcpy.Parameter(
            displayName="Input Features",
        param0.filter.type = "ValueList"
        valueList = ['Montreal', 'Toronto', 'Vancouver', 'British Columbia', 'Ontario', 'Quebec']
        param0.filter.list = valueList
        param0.values = param0.filter.list  
        return [param0]


If I don't set /comment out param0.values = param0.filter.list then I get a very similar result , just without anything selected:



New Contributor

Thanks Luke. So, as mentioned above, the issue doesn't occur in the list that gets populated when the tool opens, it's when you click on the dropdown (highlighted in the image I posted above) and then a 'sub list' pops out. It's in the sub list where the order of the list is re-sorted alphabetically.

I agree. Maybe more information is needed.

To start with, I simplified the tool a little to focus on this issue. Here is a screen grab of the parameters and their properties:


Where the properties are as follows:

Param[0] (This is a Value List that contains some options. When the user chooses one of the options, than the second parameter updates its list using some logic to re-organize the list based off of that option. This isn't the focus here, but worth noting)

  • String
  • Required
  • Input
  • Value List (populated with 'Test1', 'Test2', 'Test3')

Param[1]: This is the list that I am having issues with the ordering.

  • String (Multi Values)
  • Required
  • Input
  • Value List


My validator script is here:


class ToolValidator(object):
  """Class for validating a tool's parameter values and controlling
  the behavior of the tool's dialog."""

  def __init__(self):
    """Setup arcpy and the list of tool parameters."""
    self.params = arcpy.GetParameterInfo()

  def initializeParameters(self):
    """Refine the properties of a tool's parameters.  This method is
    called when the tool is opened."""

    valueList = ['Montreal', 'Toronto', 'Vancouver', 'British Columbia', 'Ontario', 'Quebec']
    self.params[1].filter.list = valueList


  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""

    if self.params[0].altered:

      valueList = self.processLayers(self.params[0].value)

      if not self.params[0].hasBeenValidated:
        self.params[1].filter.list = valueList
        self.params[1].values = self.params[1].filter.list 


  def updateMessages(self):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""     


  def processLayers(self, layerGroup):
    """Process the layers that will be populated in the Layer List
    in the fifth parameter of the tool. Also, this will eveluate the set of predfined layers
    found in the Predefined Layer list found in the fourth parameter of the tool."""
    if layerGroup == 'Test1':
      vList = ['Montreal', 'Toronto', 'Vancouver', 'British Columbia', 'Ontario', 'Quebec']
    elif layerGroup == 'Test2':
      vList = ['Chicago', 'Miami', 'Austin', 'Illinois', 'Florida', 'Texas']
      vList = ['Perth', 'Adelaide', 'Sydney', 'Western Australia', 'South Australia', 'New South Wales']

    return vList



Ok, so that all set up in a standalone tool in a toolbox, when you open the tool, it should look like this:



Now, choose an option (in this case, Test1) and it should look like this:



and here is the rub. When you click on the drop down arrow next to 'List' in the image above, the popout list (so that the user can check off the items they want) it re-orders alphabetically on it's own:


0 Kudos
MVP Regular Contributor

Ahhh script tool, not python toolbox. Apologies, I misunderstood you. Wonder why the behaviour is different...?  Will have a look.

Regular Contributor

Ha! Yes. Apologies. Should have been more clear. If you come up with anything @Luke_Pinner happy to test out again on my end.

0 Kudos
MVP Regular Contributor

I couldn't get your desired behaviour with a script tool. But it just works with a python toolbox.  


0 Kudos