+ Reply to Thread
Results 1 to 2 of 2

Thread: Iterating through Multivalue list of Layer Files: Error

  1. #1
    Mike MacRae
    Join Date
    Nov 2010
    Posts
    310
    Points
    32
    Answers Provided
    4


    0

    Default Iterating through Multivalue list of Layer Files: Error

    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

    Code:
    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

  2. #2
    Juan Orozco
    Join Date
    Sep 2010
    Posts
    40
    Points
    6
    Answers Provided
    1


    0

    Default Re: Iterating through Multivalue list of Layer Files: Error

    I can't see the paths that you're providing but Python does not like spaces in paths.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts