Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Import modules
- import arcpy
- from arcpy import env
- #Put file path for the folder containing mxds, where I have my sample file path
- env.workspace = r"G:GeomaticsMap Requests2017-07-24_TrailClosures"
- #Looping through all mxd documents, list layers and replace those layers MRGTrails layer with proper data source
- for file in arcpy.ListFiles("*.mxd"):
- mxd = arcpy.mapping.MapDocument('files')
- df = arcpy.mapping.ListDataFrames("*.mxd", "Layers")[0]
- for lyr in arcpy.mapping.ListLayers(mxd, "*", df):
- if lyr.name == "Trails":
- lyr.replaceDataSource(r'G:GeomaticsDataRegionalMRG.gdb', "FILEGDB_WORKSPACE", "Trails_Sentiers", validate=False)
- mxd.save()
- import arcpy
- from arcpy import env
- env.workspace = r"G:GeomaticsMap Requests2017-07-24_TrailClosures"
- for file in arcpy.ListFiles("*.mxd"):
- mxd = arcpy.mapping.MapDocument(file) # Changed 'files' to file
- # Iterate over all data frames, because what if one has a different name...or if a map has multiple data frames
- # And pass the mxd object to the function--not the mxd wildcard
- for df in arcpy.mapping.ListDataFrames(mxd):
- for lyr in arcpy.mapping.ListLayers(mxd, "*", df):
- if lyr.name == "Trails":
- lyr.replaceDataSource(r'G:GeomaticsDataRegionalMRG.gdb', "FILEGDB_WORKSPACE", "Trails_Sentiers", validate=False)
- mxd.save()
Add Comment
Please, Sign In to add comment