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:
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.filter.list = valueList self.params.values = self.params.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?
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", name="in_features", datatype="GPString", parameterType="Required", direction="Input", multiValue=True) 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:
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 (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)
Param: This is the list that I am having issues with the ordering.
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.filter.list = valueList return 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.altered: valueList = self.processLayers(self.params.value) if not self.params.hasBeenValidated: self.params.filter.list = valueList self.params.values = self.params.filter.list return def updateMessages(self): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" return 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'] else: 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: