Custom GP Script Tool - Remove item from filer.list if duplicated

410
2
Jump to solution
01-28-2023 04:08 PM
Labels (1)
julian_svcs
Occasional Contributor

I am creating a custom GP script tool and setting some validations.

The tool has a parameter to select an ArcGIS Pro APRX project and another parameter that has a dropdown list (filer.list) with the map names from the APRX project selected. The map select is a multiple option so I can select multiple maps that I want to work with in my python script (for the tool).

As it is now, I am able to select the same map multiple times. I have an error message that will show if I select a map that I have already selected, so the user will not be able to run the tool until all the maps selected are unique.

if self.params[3].altered:
    last_map_added = self.params[3].valueAsText.split(";")[-1]
    map_list_befor_last_map_added = self.params[3].valueAsText.split(";")[:-1]
    if last_map_added in map_list_befor_last_map_added:
        self.params[3].setErrorMessage(f"\"{last_map_added}\" already exists in Map List.\nPlease remove this map from Map List.")

Is it possible to remove the duplicated map from the selected map list instead of just showing an error message.

Thanks for any help.

Julian.

0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor

Just guessing, could it be as simple as?

 

self.params[3].value = self.params[3].valueAsText.split(";")[:-1]

 

View solution in original post

2 Replies
DuncanHornby
MVP Notable Contributor

Just guessing, could it be as simple as?

 

self.params[3].value = self.params[3].valueAsText.split(";")[:-1]

 

julian_svcs
Occasional Contributor

How embarrissing. It was that simple.

Thanks for the quick response @DuncanHornby