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


Reply With Quote
Bookmarks