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
  • please try to form one question. Make it have a question mark at the end. A clear question will likely get an answer quicker than asking for guidance.
    – Brad Nesom
    May 27, 2015 at 18:50
  • Take a look at this: gis.stackexchange.com/questions/35553/…
    – KHibma
    May 27, 2015 at 20:20

5 Answers 5

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)
3
  • This was very helpful. Thanks! I figured out something that is working...now to just fully understand WHY. =)
    – GYS
    May 27, 2015 at 20:45
  • @GYS can you elaborate for future reference?
    – DWynne
    May 27, 2015 at 23:32
  • @GYS don't forget to choose an answer when you get a chance.
    – ianbroad
    May 28, 2015 at 0:42
2

Use split to convert parameter to list expected by Merge.

inputLayer = arcpy.GetParameterAsText(1)

list2merge=inputLayer.split(";")
1
  • Could you please elaborate on how you would use split?
    – Aaron
    May 27, 2015 at 19:52
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
1

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, "")
0

This is what I needed to do in order to use a list of feature classes listed in a text file. A little off topic since the OP is specifically asking about GetParameterAsText() and I'm side-stepping the function. It is however directed at the same end goal: feeding Merge_managment a long list of inputs.

import arcpy

#inputLayer = arcpy.GetParameterAsText(1)
#outputFC = arcpy.GetParameterAsText(2)

inputLayer = r"X:\source\all-footprint-featureclasses.txt"
outputFC = r"X:\work\default.gdb\all_sat_footprints"

ff = open(inputLayer)

# Open text file and put each line into a list element
#   --> ["path1","path2", ...]
layerList = ff.read().split()

print(f"{layerList[0:1]}...")
arcpy.Merge_management(";".join(layerList), outputFC, "")
  # ";".join() turns ["path1","path2"] into --> "path1;path2"
print(arcpy.GetMessages())

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.