ArcPy script tool parameter for nested arrays?

416
3
01-12-2024 08:17 PM
aakims
by
New Contributor II

I have an arcpy script I'd like to turn into a script tool, but I am not sure if what I need for one of my parameters is feasible with the existing data type options.

The parameter is a two-dimensional array with both levels having variable lengths. Here is an example just to demonstrate the structure:

[[A, 1, 2, 3], [B, 4, 5], [C, 1, 5], [D, 2], ...] 

I think what I would ideally want is a value table parameter that can take a multivalue parameter for one of its columns.  

This script automates frequently repeated manual tasks for my team, so there is no spatial data computation/analysis happening. So while this may not be the best object structure, it works well for our purpose. I want an option to construct this parameter using the Pro's tool interface since the numeric variables in the above example are feature layers from the map. While it's doable, writing out their paths manually sometimes is time-consuming and prone to error. 

Any suggestions you can offer to achieve this? Thanks in advance for your help. 

0 Kudos
3 Replies
BlakeTerhune
MVP Regular Contributor

I can't think of how this (with variable lengths) would fit into any parameter data type besides GPString. Does that work?

DavidSolari
Occasional Contributor III

You could maybe get jagged arrays working with a ValueTable but you might run into ergonomics issues. My preferred solution is a multivalue string parameter where each value is delimited with a known character. As long as you validate each value in the updateParameters validation step you should be good to go.

0 Kudos
KimOllivier
Occasional Contributor III

Have a look at the validation tools in the forms. You can program up a really complex interface with a bit of python programming, have error messages and check it is valid before starting the run. You can even program the whole form up in python so you don't use the wizard at all, I haven't gone to that step myself.

Here is an example that analyses our census data. http://www.ollivier.co.nz/support/census2018/index.htm

0 Kudos