1

I am pretty new to ArcPy so bear with me. I am having a hard time understanding how to feed a list of FCs from a "GetParameterAsText" into something like the merge tool. I have my GetParamterAsText window set to Feature Class and multivalue so I can drag a group of layers into it in the tool dialogue.

inputLayer = arcpy.GetParameterAsText(1)

When I run the merge command, it looks like it is messing up the expected syntax by putting ";" as a separator instead of ",".

Doing this:

arcpy.Merge_management(inputLayer, outputName, "")

Throws me this error:

"C:\Development\Merge_Dissolve\GA0combined.shp;C:\Development\Merge_Dissolve\GA25combined.shp" does not exist

I have tried to create a function to replace ";" with ",", but it doesn't seem to work on my inputLayer variable, but I'm guessing there's a more standardized way to working with a list of FCs with tools that accept multiple inputs such as Merge.

2

Use split to convert parameter to list expected by Merge.

inputLayer = arcpy.GetParameterAsText(1)

list2merge=inputLayer.split(";")
  • Could you please elaborate on how you would use split? – Aaron May 27 '15 at 19:52
3

try

parameter = arcpy.GetParameter(1)
inputLayers = parameter.values()

This should give you the different layers as a list Afterwards you can access the individual layers by index or in a loop

layer = inputLayers[0]

or

for layer in inputLayers:
   (do something with your layer)
  • This was very helpful. Thanks! I figured out something that is working...now to just fully understand WHY. =) – GYS May 27 '15 at 20:45
  • @GYS can you elaborate for future reference? – DWynne May 27 '15 at 23:32
  • @GYS don't forget to choose an answer when you get a chance. – ianbroad May 28 '15 at 0:42
1

There are several ways of successfully formatting values for a tool that accepts multivalues in Python.

  1. A semi-colon delimited string of data is a valid input for any geoprocessing parameter that accepts multiple inputs. This is valid, and is what you will be getting from GetParameterAsText on a multivalue parameter.
  2. A list of strings of the feature classes (or layers, or table views, or whatever the tool parameter accepts).
  3. A list of arcpy.Value objects. If you use GetParameter this is what you should be getting.
  4. Create and populate an arcpy.ValueTable object. I don't recommend this per se as it's more effort than it's worth, but it will work.

If you've done #1, and it's not working, I would question whether the data does exist.

0

So the answer was that I needed to create a list and then feed that into the merge command. I'm not sure why #1 didn't work from @DWynne as that has worked for me in the past (and how I approached this at first) on another tool that takes multiple inputs.

This was my basic flow:

inputLayer = arcpy.GetParameterAsText(1)
layerList = inputLayer.split(";")
arcpy.Merge_management(layerList, tempmergeName, "")

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.