3

I have scripted tools in ArcPy that gather inputs using "GetParameterAsText", which then show up in the tool GUI like this:

enter image description here

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.

enter image description here

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.

2
  • 1
    Please 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
    Commented Dec 5, 2017 at 23:59
  • Thanks - I've edited my question and tags to indicate Arc 10.2
    – Waterman
    Commented Dec 6, 2017 at 0:14

2 Answers 2

4

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:

enter image description 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.

4
  • That's perfect! And thanks for the follow up script to show how to convert the inputs into something usable.
    – Waterman
    Commented Dec 6, 2017 at 0:17
  • 1
    Is ConversionUtils actually needed? I usually just use inputs.split(";") to get a list from the semi-colon separated string.
    – PolyGeo
    Commented Dec 6, 2017 at 0:33
  • 1
    That 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
    Commented 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
    Commented Dec 6, 2017 at 1:24
2

Using the multivalue parameter control enables you to:

Drag and drop single or multiple layers from ArcMap onto the list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.