Script Tool Multivalue Check Boxes Not Updating

478
8
11-04-2021 09:01 AM
EvanMyers1
New Contributor III

I have been trying to figure out why the Multivalue boxes in my tool don't respond with the "Select All" and "Unselect All" buttons.  They also don't stay unchecked (they are default checked) when I click other buttons.

Here is my validation code (the commented out part at the bottom was my attempt but I get errors):

 

import arcpy
import os


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."""
        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[1].value:
            if self.params[1].valueAsText.find(";") > -1:
                fclist = self.params[1].valueAsText.split(";")
                layerList = []
                for each in fclist:
                    # source = arcpy.Describe(each).catalogPath
                    # desc = arcpy.Describe(each)
                    # layersource = desc.catalogPath
                    layerList.append(each)
                print layerList
            else:
                layerList = []
                # desc = arcpy.Describe(self.params[0].value)
                # layersource = desc.catalogPath
                # layerList.append(layersource)
                layerList = [self.params[1].valueAsText]
                print layerList
            fieldlist = []
            for each in layerList:
                #fieldnames = [f.name for f in arcpy.Describe(each).fields]
                fieldnames = arcpy.Describe(each).fields
                for fields in fieldnames:
                    if fields not in fieldlist:
                        #fieldlist.append(fields)
                        fieldlist.append(fields.baseName.upper())
            self.params[2].value = fieldlist
            print fieldlist
            # if self.params[1].hasBeenValidated:
            #     for checked in self.params[2].valueAsText.split(';'):
            #         if checked not in self.params[2].filter.list:
            #             self.params[2].value = self.params[2].filter.list[2]

        return

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

 

EvanMyers1_0-1636059253706.png

Any help would be appreciated.  Thank you!

0 Kudos
8 Replies
JeffK
by MVP Regular Contributor
MVP Regular Contributor

I think that this

if fields not in fieldlist:

is checking if the field object is in the fieldlist but it should be checking  fields.name.upper() in fieldlist since you are appending the field's basename's to the list.

0 Kudos
EvanMyers1
New Contributor III

I tried your suggestion but it caused my field pick list to be blank.  I have added a picture of my tool to better illustrate

0 Kudos
JeffK
by MVP Regular Contributor
MVP Regular Contributor

I think .value allows for objects, so its parsing the field name from the field object in your multivalue there.  Have you tried setting the filter list to the param filter, instead of the value?  You may need to apply my previous suggestion of field names.

fcFilter = self.params[2].filter
fcFilter.list = filterlist

 

0 Kudos
EvanMyers1
New Contributor III

Can you clarify which line this change should go?  I tried it on line 47 and my field list doesn't populate.  

0 Kudos
EvanMyers1
New Contributor III

Has anyone else figured out how this function works?  This is still an issue for me.

0 Kudos
JeffK
by MVP Regular Contributor
MVP Regular Contributor

This block of code lets me choose multiple items/ select all and deselect all works. in my 3rd parameter:

def updateParameters(self):
    if self.params[2].value:
        fcFilter = self.params[3].filter
        iniPath = r"{}".format(self.params[2].valueAsText)
        attributevalues = list(set([line.strip().split('.')[1] for line in open(iniPath)]))
        attributevalues.sort()
        fcFilter.list = attributevalues

 

line 47 in your code would be replaced, did you also try with a list of fieldnames instead of a list of field objects?

 

0 Kudos
JeffK
by MVP Regular Contributor
MVP Regular Contributor

Another thing you can try to do is work backwards because its hard to debug this class. Create a hard coded list and get that to display/ work correctly and then manipulate your incoming data to be structured exactly like the pseudo list.

0 Kudos
EvanMyers1
New Contributor III

Thank you for providing a piece of your code, but this did not work for me.  

I need to use feature layers inside arcmap for my tool to work properly.  I cannot use a file path.  There are only two issues that prevent my script from working and it comes down to the Validator.

1.  If the layers are in a group it will not work at all.  E.g. "IOError: "'New Group Layer\wControlValve'" does not exist".  On line 42, arcpy.Describe(each).fields, isn't working.

2.  If I ungroup my layers, the field list populates, but now none of the boxes will stay unchecked, making my tool useless.

Right now, the way I have my code works to an extent, it is my lack of understanding why the boxes wont stay unchecked.

 

0 Kudos