1

I am looking at making a Python script 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?

  • 1
    Are you creating a python toolbox script (.pyt) or a script tool in a regular toolbox (.tbx)? – user2856 Feb 13 '14 at 23:56
  • I am creating a script tool in a toolbox. – user25074 Feb 14 '14 at 0:00
  • 1
    If neither of the Answers offered so far are Accept-able then I think we need more details, like a working code snippet with hard coded examples of the variable values you are hoping to pass in as parameters, edited into your Question. – PolyGeo Mar 2 '14 at 10:46
5

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.

| improve this answer | |
  • Thanks, but it won't actually let me type anything into the MultiValue property, any thoughts on that? – user25074 Feb 14 '14 at 0:08
  • @user25074 - You don't type "Yes", it's a dropdown/pick list. Click on "No" and select "Yes" instead. – user2856 Feb 14 '14 at 0:19
  • @user25074 - If you mean you can't type anything when trying to run the tool (as opposed to setting the parameter properties). If you have set your parameter type to "String", change it to "Any Value". – user2856 Feb 14 '14 at 0:22
1

You can use the sys module or arcpy module to input these arguments: i.e.

import sys,arcpy
# Version 1 - this will give you a python list of the arguments you enter
input_arguments = sys.argv
# i.e. input_arguments will = ['abc,123','def,456']

# Version 2

first_argument = arcpy.GetParameter(0)
second_argument = arcpy.GetParameter(1)

etc.

| 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.