0

I've created a small toolbox where I use a GPString input with a filter list:

param1 = arcpy.Parameter(
    displayName="OSM tag value",
    name="in_key",
    datatype="GPString",
    parameterType="Required",
    direction="Input",
    multiValue=True
)
param1.filter.list = self.getConfig("tags")

The function getConfig reads a JSON and fills the values of the String input. Yet I want to enable the user to use an own string for the input at param1.

Is there any chance to do this with the given approach or do I need to create a second input for a user defined GPString?

Here is the issue on GitHub.

1

I would use GPValueTable instead of GPString to have plus button for adding user entries but this makes things a bit tricky since you need to set columns and work out filter updating mechanism. I ran a small test and I think rough workaround below might be of help.

After setting datatype="GPValueTable" you need these lines below

param1.columns = [['String', 'Desired Tags']]
param1.filters[0].type = 'ValueList'
# These are optional default values if needs be. If not just comment out the line below
param1.values = [['A place'], ['Or Not']]
param1.filters[0].list = self.getConfig("tags")

and you need to setup updateParameters as follows to add new user entries to filter list. You can even update your config file here or around execute:

def updateParameters(self, parameters):
    if parameters[1].altered:
        new_values = [i[0] for i in parameters[1].values if i[0] not in parameters[1].filters[0].list]
        parameters[1].filters[0].list += new_values

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.