AnsweredAssumed Answered

replaceDataSource for layers within a group layer

Question asked by timmo1982 on Nov 11, 2013
Latest reply on Nov 11, 2013 by timmo1982
I've written a script to support a move to file geodatabases- It basically updates standard layer files (.lyr) to point to the .gdb database instead of the .mdb database. It works for simple layers but I can't get it to update layers within a group layer.

Here's the relevant code- The tool fails at the with a 'AssertionError: No filename set'

for layerFile in arcpy.ListFiles("*.lyr"): # find the actual layer files in the folder     arcpy.AddMessage("Found layer file: " + str(layerFile))     lyr = arcpy.mapping.Layer(folder + "\\" + layerFile) # make layer object from layer file      for lyrObj in arcpy.mapping.ListLayers(lyr):# a layer file may have multiple layers within it so work through those...         if lyrObj.isGroupLayer == 1: # if it is a group layer             arcpy.AddMessage("This layer file contains grouped items")             for item in lyrObj:                 arcpy.AddMessage("It contains a layer object named: " +                 newWS = item.workspacePath.replace(".mdb", ".gdb")                 newSource = item.dataSource.replace(".mdb", ".gdb")                 arcpy.AddMessage("dataSource: " + newWS)                 if arcpy.Exists(newSource):                     arcpy.AddMessage("I've found a replacement GDB for this so I'll update this layer.")                     item.replaceDataSource (newWS, "FILEGDB_WORKSPACE")                  else:                     arcpy.AddMessage(newSource + " DOES NOT exist. Will not update this layer.")   

The same method works for saving a non-grouped layer and I've tried saving the 'item' as well....Any ideas?