Select to view content in your preferred language

Remove Option from Toolbox Parameter Value List if Selected

1477
10
Jump to solution
11-11-2022 01:09 AM
Labels (2)
RichardHowe
Frequent Contributor

I have a tool which has a string parameter with a predefined value list filter, allowing the user to select multiple options from a dropdown list in the GUI.

However, when they select one option, I would then like that option to be removed from the list which they  choose the next option from. Is this possible, and if so how? In an ideal world it would be the default behavior, because I struggle to think of why you would want to put the same option in twice as a user, but you can.

In the image below the Value List filter comprises A, B, C and D. As you can see the user has chosen A for the first entry and B for the second. I would like the options for the next entry to just be C and D, so they can't errantly pick A or B again...but that isn't the case.

RichardHowe_0-1668157826483.png

 

I feel perhaps some kind of validation is probably the answer to this, but I can only find documentation to make individual parameters dependent on another parameter, not on entries for the same multi value parameter.

0 Kudos
1 Solution

Accepted Solutions
tyler_fossett
New Contributor

Hey Richard,

I feel obligated to reply because the response you received is incorrect... I achieved what you are describing.  My approach would look something like this with your situation:

def updateParameters(self, params):
    filtervals = ['A', 'B', 'C']
    try:
        ## create a list of previously selected values from filter list
        paramvals = params[0],valueAsText.split(";")  
        ## remove selected values from temporary filter list 
        for val in paramvals:
            ## list of selected values contains apostrophes, so must remove them
            filtervals.remove(val.replace("'",""))
        ## reassign filter list after removing selected values
        params[0].filters[0].list = filtervals
    except:
        ## this avoids error message if user has not selected anything
        pass

def updateMessages(self, params):
    ## removing previously selected items from the filter list creates an error message 
    ## next to previously selected items saying they are not in the list... 
    ## the tool still works as intended, so I just clear that message to make it look cleaner
    params[0].clearMessage()

Anyways, I wanted to share because I almost gave up after reading the response to your question.  It seems more intuitive for it to behave like you describe though.

Cheers

 

 

View solution in original post

10 Replies
DanPatterson
MVP Esteemed Contributor

To ensure sorted order

vl = ['A', 'A', 'B', 'C', 'D', 'D']
out = sorted(list(set(vl)))
out
['A', 'B', 'C', 'D']

 and uniqueness in your validation 


... sort of retired...
0 Kudos
RichardHowe
Frequent Contributor

Dan, thanks. I understand how to script for removing accidental duplicate picks, that isn't an issue. I just don;t want them to be able to do it. It just seems illogical that it will show already selected values in the dropdown

0 Kudos
DanPatterson
MVP Esteemed Contributor

unless you want to use the value list to process things in a certain order with repeats, like recalculating coordinates for featureclasses in different coordinate sytems (eg. 'A', 'A', 'B') some with repeats, others without


... sort of retired...
0 Kudos
RichardHowe
Frequent Contributor

Perhaps I'm not being particularly clear. Apologies.

If the user picks A for the first entry, then I don;t want A to appear in the list of options they can pick from in the next row. Imagine if this was the delete fields tool, it wouldn't allow the user to pick the same field to delete twice, once it was selected once, then it wouldn't be in the list of options they could pick to delete at the same time

0 Kudos
DanPatterson
MVP Esteemed Contributor

In my example I was clear about enabling the user to be able to select the same input more than once in an order that I want for processes that provide a list for me to process.  If your workflow requires unique entries, then do this during validation of the inputs.  In that fashion, the widest possible uses of a value list can be attained, eg. those with unique values or not, those in any order or not.  Different workflows shouldn't be disabled because or user preferences may differ


... sort of retired...
0 Kudos
RichardHowe
Frequent Contributor

I still don't think you understand my question. I am providing a pre-populated value list filter for a single parameter, that allows multiple values. That single parameter shows the dropdown list to the user in the toolbox GUI and they can pick an item from it, then, if they wish to pick another item from it, for the same parameter, they can. However I don't want them to be able to select the same value again and I still can't visualise a use case for picking exactly the same value as a second input to the same parameter. Regardless of which, I would like to know how to prevent it happening.

0 Kudos
DanPatterson
MVP Esteemed Contributor

I understand your use case. 

I have mine which I have provided an example for.

I wouldn't want your workflow to be the only one.

And there is no way to disable it.


... sort of retired...
0 Kudos
tyler_fossett
New Contributor

Hey Richard,

I feel obligated to reply because the response you received is incorrect... I achieved what you are describing.  My approach would look something like this with your situation:

def updateParameters(self, params):
    filtervals = ['A', 'B', 'C']
    try:
        ## create a list of previously selected values from filter list
        paramvals = params[0],valueAsText.split(";")  
        ## remove selected values from temporary filter list 
        for val in paramvals:
            ## list of selected values contains apostrophes, so must remove them
            filtervals.remove(val.replace("'",""))
        ## reassign filter list after removing selected values
        params[0].filters[0].list = filtervals
    except:
        ## this avoids error message if user has not selected anything
        pass

def updateMessages(self, params):
    ## removing previously selected items from the filter list creates an error message 
    ## next to previously selected items saying they are not in the list... 
    ## the tool still works as intended, so I just clear that message to make it look cleaner
    params[0].clearMessage()

Anyways, I wanted to share because I almost gave up after reading the response to your question.  It seems more intuitive for it to behave like you describe though.

Cheers

 

 

RichardHowe
Frequent Contributor

Tyler, you legend. Thank you!!!