Guest User

Untitled

a guest
Jun 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #Import modules
  2. import arcpy
  3. from arcpy import env
  4.  
  5. #Put file path for the folder containing mxds, where I have my sample file path
  6. env.workspace = r"G:GeomaticsMap Requests2017-07-24_TrailClosures"
  7.  
  8. #Looping through all mxd documents, list layers and replace those layers MRGTrails layer with proper data source
  9. for file in arcpy.ListFiles("*.mxd"):
  10. mxd = arcpy.mapping.MapDocument('files')
  11. df = arcpy.mapping.ListDataFrames("*.mxd", "Layers")[0]
  12. for lyr in arcpy.mapping.ListLayers(mxd, "*", df):
  13. if lyr.name == "Trails":
  14. lyr.replaceDataSource(r'G:GeomaticsDataRegionalMRG.gdb', "FILEGDB_WORKSPACE", "Trails_Sentiers", validate=False)
  15.  
  16. mxd.save()
  17.  
  18. import arcpy
  19. from arcpy import env
  20.  
  21. env.workspace = r"G:GeomaticsMap Requests2017-07-24_TrailClosures"
  22.  
  23. for file in arcpy.ListFiles("*.mxd"):
  24. mxd = arcpy.mapping.MapDocument(file) # Changed 'files' to file
  25. # Iterate over all data frames, because what if one has a different name...or if a map has multiple data frames
  26. # And pass the mxd object to the function--not the mxd wildcard
  27. for df in arcpy.mapping.ListDataFrames(mxd):
  28. for lyr in arcpy.mapping.ListLayers(mxd, "*", df):
  29. if lyr.name == "Trails":
  30. lyr.replaceDataSource(r'G:GeomaticsDataRegionalMRG.gdb', "FILEGDB_WORKSPACE", "Trails_Sentiers", validate=False)
  31. mxd.save()
Add Comment
Please, Sign In to add comment