AnsweredAssumed Answered

replaceDataSource in layer file (not mxd)

Question asked by bmaier1955 on May 8, 2013
Latest reply on May 14, 2013 by jbarrette-esristaff
My world: Win7, ArcGIS 10.0  SP1, Python 2.6.5

I am attempting to update a group layer file with new data source locations (FGDB moved from one location to another location). I get no errors running this code, but the new file locations are not updated in the layer file.  Most of the discussions in this forum (related to this issue) are related to using an mxd, but in my case, I want to update a layer file (*.lyr). 

  • Have verified that the paths are correct (via print statements).

  • Have verified that i am updating feature classes and that they support the DATASOURCE property

  • Have also tried saving the .lyr file using "arcpy.mapping.Layer(inLayerFile).saveACopy("newfilename")"

  • I have tried findAndReplaceWorkspacePath with no success.

  • Have tried converting newPath variable to unicode - again no success.

Any help greatly appreciated!

#  import sys, os import arcpy  outFolder = r"C:\Projects\CoreData\GeoName" newFolder = r"C:\projects\testmove\test2\GeoName"  inLayerFile = r"C:\projects\testmove\test2\GeoName\LayerFiles\AG10\BaseInfo.lyr"  for lyr in arcpy.mapping.Layer(inLayerFile):   pout = lyr.isFeatureLayer   if pout == True:     if lyr.supports("DATASOURCE"):       currWSPath = str(lyr.workspacePath)       scol = str.upper(currWSPath).find('GEONAME')       scol = scol + len('GEONAME') + 1       newPath = newFolder + os.sep + currWSPath[scol:]       print + " | Path: " + newPath + " | DSN: " + lyr.datasetName       lyr.replaceDataSource(unicode(newPath), 'FILEGDB_WORKSPACE', lyr.datasetName, True)     else:       print "Layer " + + " does not support datasource changes"   else:     pass