Iterating through Multivalue list of Layer Files: Error

712
1
09-30-2011 10:15 AM
MikeMacRae
Occasional Contributor III
Hey all,

I am trying to iterate through a multivalue list of layer files from a parameter (set as a "Layer File" type). I've been trying to loop through the list, but it either errors out or I only get the first layer file returned. In the following script, I'm trying to set the sourceLayer to one of the layer files being fed from a multivalue list. It keeps returning the error:


PYTHON ERRORS:
Traceback info:
  File "Z:\ESRI\Python\Test Scripts\UpdateLayer.py", line 52, in <module>
    sourceLayer = arcpy.mapping.Layer(lyrFile)

Error Info:
Object: CreateObject Layer invalid data source



folderPath = arcpy.GetParameterAsText(0)
layers = arcpy.GetParameterAsText(1).split(";")

for filename in glob.glob(os.path.join(folderPath, "*.mxd")):
    fullpath = os.path.join(folderPath, filename)
    mxd = arcpy.mapping.MapDocument(filename)

    if os.path.isfile(fullpath):
        basename, filename2 = os.path.split(fullpath)

    for df in arcpy.mapping.ListDataFrames(mxd, "*"):
        for lyr in arcpy.mapping.ListLayers(mxd, "*", df):
            for lyrFile in layers:

                if lyr.name == "Land Area":
                    if "Development" in lyrFile:
                        arcpy.AddMessage(lyr.name)
                        arcpy.AddMessage(lyrFile)
                         sourceLayer = arcpy.mapping.Layer(lyrFile)
                         arcpy.mapping.UpdateLayer(df,lyr, sourceLayer, True)
                         del sourceLayer

                if lyr.name == "Disturbed Land":
                    if "Disturbed Land" in layers:
                        arcpy.AddMessage(lyr.name)
                        arcpy.AddMessage(lyrFile)
                         sourceLayer = arcpy.mapping.Layer(lyrFile)
                         arcpy.mapping.UpdateLayer(df,lyr, sourceLayer, True)
                         del sourceLayer

    mxd.save()
    del mxd
Tags (2)
0 Kudos
1 Reply
JuanOrozco
Occasional Contributor
I can't see the paths that you're providing but Python does not like spaces in paths.
0 Kudos