1

I'm using a Value Table as a parameter for a Python toolbox so the user can input two related attributes. I'm struggling with how to use the values the user inputs as separate values/parameters. The code for my value table parameter looks like this:

    target_elements = arcpy.Parameter(
        displayName = "Target Element(s) Name",
        name = "element_name",
        datatype = "GPValueTable",
        parameterType = "Required",
        multiValue = True,
        direction = "Input")
    target_elements.columns = [['GPString','Target Element'],['GPString','EO ID (if known)']]
    target_elements.filters[0].type = 'ValueList'
    target_elements.filters[0].list = sorted(list(et_all.values()))

This code is giving me the desired toolbox operation. However, if the user input is "Abagrotis anchocelioides" for the first column and "53910" for the second column, the resulting output is a string that puts them together like this:

'Abagrotis anchocelioides' 53910

I'm not sure how to separate these values so that I can use them separately. I can't split on spaces because the first value often contains two words.

Is there another way to do this, or should I be using a different parameter type?

  • 2
    How are you querying your value table to return the string, albeit incorrect? – Hornbydd Feb 14 at 18:17
  • I can split up the multivalue inputs with target_elements.split(";"). But, I've tried different ways to split up the individual rows with x.split("'") or x.split(" "), but this doesn't work since the first input value sometimes includes one word and sometimes includes two words. – mmoore Feb 14 at 20:35
4

I was calling my parameter with the line:

target_elements = params[0].valueAsText

I needed to be calling the parameter as a value:

target_elements = params[0].value

This gave a list of values and is exactly what I wanted.

| improve this answer | |

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.