[GIS] Getting Python script tool to take list of variables

arcgis-desktoparcpypython-script-tool

I am looking at making a Python script tool that requires the user to input a series of attributes into a list, which is then used to build a query, to select multiple polygons (i.e. "abc, 123"; "def, 456").

I understand how to script this, but how do I get the script tool to take the arguments?

Best Answer

If you are creating a script tool in a regular toolbox, when defining the tools parameters, for the parameter you want to pass as a list, set the "MultiValue" property to Yes. The multiple values will get passed to your script as a semi-colon separated string. To use as a list in your python script, split the string on the semi-colon, i.e:

lst_arg=arcpy.GetParameterAsText(n).split(';')

See this help topic for more information on script tool parameters.