2

enter image description here When I click on the Select All, it doesn't work (using ArcGIS 10.3.1 Advanced). How can I fix this?

The Python Script for this model is listed below, from the online source rather than my creation.

# Import system modules
import arcpy

# Set the parameters
InputFeatureClass = arcpy.GetParameterAsText(0)
InputField = arcpy.GetParameterAsText(1)
InputValue = arcpy.GetParameterAsText(2)

arcpy.SetParameter(3, InputValue)

The parameter validation code is listed, also from the online source.

import arcpy
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()
    self.fcfield = (None, None)

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

  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parmater
    has been changed."""
    if self.params[0].value and self.params[1].value:
      fc, col = str(self.params[0].value), str(self.params[1].value)
      if self.fcfield != (fc, col):
        self.fcfield = (fc, col)
        self.params[2].filter.list = [str(val) for val in
                                        sorted(
                                          set(
                                            row.getValue(col)
                                            for row in arcpy.SearchCursor(fc,
                                                                          fields=col)
                                              )
                                           )
                                      ]
        if self.params[2].value not in self.params[2].filter.list:
          self.params[2].value = self.params[2].filter.list[0]

  def updateMessages(self):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""
    return
4
  • Does it (3rd parameter) have MultiValue set to Yes?
    – FelixIP
    Mar 13, 2017 at 2:49
  • Yes. Otherwise, it will show the dropdown list rather than the check box.
    – Tianxin Li
    Mar 13, 2017 at 3:03
  • Perhaps try to change field type to any. Arcgis struggling with multivalue, text
    – FelixIP
    Mar 13, 2017 at 3:27

1 Answer 1

2

I believe the issue is with these lines:

if self.params[2].value not in self.params[2].filter.list:
  self.params[2].value = self.params[2].filter.list[0]

It is trying to protect the input by setting the value to the first item in the filter list if the current value is not in the filter list.

From my experimenting (in 10.1 so I had to adjust some of the code and may have introduced some other error), the value of self.params[2] was a semi-colon delimited list: American Coot; Black Scoter

When comparing that to the filter.list, it would always be false, so it would reset the value.

So try to comment out those lines and see if Select All works.

Here is some hacky code that tries to do a slightly better job:

if parameters[2].value:
    for checked in parameters[2].valueAsText.split(';'):
        if checked not in parameters[2].filter.list:
            parameters[2].value = parameters[2].filter.list[0]
            break

It splits of the current parameter 2 values into a list, then goes through the select list looking for each in the filter list. If any one is missing, it defaults the value to the first one. That may not be what you want, but could give you some idea what is possible here.

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.