AnsweredAssumed Answered

replaceDataSource script for toolbox

Question asked by bogdanpalade on Oct 10, 2012
Latest reply on Oct 22, 2012 by bogdanpalade
Dear all,

I have written a small script that looks in many mxds and updates a certain layer's data source with another's. When it is hardcoded it works well. I tried to include it in a toolbox, it runs, raises no errors, but it does not do nothing. I ve been trying for the last 2 days and I do not succeed in finding what's happening.

here is the code:

import arcpy, os folderPath = arcpy.GetParameterAsText(0) #path to mxds Name = arcpy.GetParameterAsText(1)#Name of bad layer in mxds DataS= arcpy.GetParameterAsText(2)#path to new workspace NewS= arcpy.GetParameterAsText(3)#new dataset    for filename in os.listdir(folderPath):     fullpath = os.path.join(folderPath, filename)     if fullpath[-4:] == ".mxd":         mxd = arcpy.mapping.MapDocument(fullpath)         for df in arcpy.mapping.ListDataFrames(mxd):             lyrs = arcpy.mapping.ListLayers(df)             for lyr in lyrs:                 if == Name:                     lyr.replaceDataSource(DataS, "SHAPEFILE_WORKSPACE",NewS,True) del mxd

Thank you very much,