I have scripted tools in ArcPy that gather inputs using "GetParameterAsText", which then show up in the tool GUI like this:
But that is for gathering a single file by navigating to it and selecting it.
I want to script a tool that allows the user to drag multiple layers from the Table of Contents, just like the "Batch Project" tool below.
What is the proper scripting syntax to generate the same input field as "Input Feature Class or Dataset", and also the large field below it where the multiple layers are displayed? I am using Arc version 10.2.
-
1Please Edit the question to specify the exact version of ArcGIS in use. You have a 10.0 tag, which is incompatible with most Python toolbox functionality.Vince– Vince2017年12月05日 23:59:04 +00:00Commented Dec 5, 2017 at 23:59
-
Thanks - I've edited my question and tags to indicate Arc 10.2Waterman– Waterman2017年12月06日 00:14:18 +00:00Commented Dec 6, 2017 at 0:14
2 Answers 2
When you go to create your script in ArcMap or Catalog, you'll want to go into the properties dialog and set your input field (of any type you need) to allow Multi Values, as circled in red here:
This allows the user to input either a single layer, file, or whatever the field dictates, or input as many as they need. In the actual arcpy script/code, the standard handling for working with these inputs is as follows:
import arcpy
import ConversionUtils #should be pathed correctly with ArcGIS/arcpy installation
inputs = ConversionUtils.gp.GetParameterAsText(0)
inputs = ConversionUtils.SplitMultiInputs(inputs)
for input in inputs:
arcpy.Project_management(...)
#Perform your individual actions here
Bear in mind that the ConversionUtils get parameter as text call returns all the user inputs as a string, separated by a semicolon. The second line to split them there separates them out into a standard list, which you can then iterate through or do whatever you want with.
-
That's perfect! And thanks for the follow up script to show how to convert the inputs into something usable.Waterman– Waterman2017年12月06日 00:17:42 +00:00Commented Dec 6, 2017 at 0:17
-
1Is
ConversionUtils
actually needed? I usually just useinputs.split(";")
to get a list from the semi-colon separated string.2017年12月06日 00:33:01 +00:00Commented Dec 6, 2017 at 0:33 -
1That would work equally well and save an import; the only reason I have used the ConversionUtils.py in the past is because that's what I had always encountered when editing existing (native) batch scripts, or using these as a starting point for a new script.AlecZ– AlecZ2017年12月06日 00:44:55 +00:00Commented Dec 6, 2017 at 0:44
-
@AlecZ Thanks for your help but I'm having trouble using the "inputs" in my loop. I've posted my code in a Question entitled "How to Assign String to "Layer" in ArcPy", in case you can help again.Waterman– Waterman2017年12月06日 01:24:50 +00:00Commented Dec 6, 2017 at 1:24
Using the multivalue parameter control enables you to:
Drag and drop single or multiple layers from ArcMap onto the list.
Explore related questions
See similar questions with these tags.