mkoneya

How to add List of LayerFiles To Map

Discussion created by mkoneya on Jun 9, 2011
Latest reply on Jun 10, 2011 by mkoneya
How do I create a list of Layer Files to add to a map?

I am using arcpy.GetParameterAsText to get the layer file(s),  but I can't get it to work with a list.   If I run the open the script in ArcCatalog,  I can only put in one layer file and not a list.   I tried to add more files delmited by commas in the dialog, but that did not work.

Below is the code that I am using:

import arcpy
mapDoc = arcpy.GetParameterAsText(0)
lyrFiles = arcpy.GetParameterAsText(1)
layers = [lyrFiles]
mxd = arcpy.mapping.MapDocument(mapDoc)
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyrFile in layers:
lyr = arcpy.mapping.Layer(lyrFile)
arcpy.mapping.AddLayer(df, lyr) 
arcpy.RefreshActiveView() 
arcpy.RefreshTOC()
mxd.save()

Thanks,

Mele

Outcomes