Find and Replace shapefile source script not working

المشرف العام

Administrator
طاقم الإدارة
I'm very new to python so please forgive me if this is a simple error.I have quite a few MXD's in which each have a few layers referencing the same source. However I have since moved this data to a new folder.I have written a script to automatically refresh the similar layers.

The script runs through, however when I check to see if its worked, none of the layers are refreshed. I'm not sure whats wrong.

import arcpy, os#workspace to search for MXDsWorkspace = r"M:\TEAM_GIS\EDKM\Projects\mmo1065_south_habitat_mapping\20140708_Update_3_QA\3_Working_GIS_Files\MXD"arcpy.env.workspace = Workspace#list map documents in foldermxdList = arcpy.ListFiles("*.mxd")print mxdList#set new link for specific shapefile in each MXD in list.for file in mxdList:#set map document to change filePath = os.path.join(Workspace, file) mxd = arcpy.mapping.MapDocument(filePath)for lyr in arcpy.mapping.ListLayers(mxd): if lyr.supports("DATASOURCE"): if lyr.dataSource == r"M:\TEAM_GIS\EDKM\Projects\mmo1065_south_habitat_mapping\20140708_Update_3_QA\3_Working_GIS_Files\WP1\MMO_South_Plan_Areas.shp": lyr.findAndReplaceWorkspacePath(r"M:\TEAM_GIS\EDKM\Projects\mmo1065_south_habitat_mapping\20140708_Update_3_QA\3_Working_GIS_Files\WP1", r"M:\TEAM_GIS\EDKM\Projects\mmo1065_south_habitat_mapping\20140708_Update_3_QA\3_Working_GIS_Files\SHP") if lyr.dataSource == r"M:\TEAM_GIS\EDKM\Projects\mmo1065_south_habitat_mapping\20140708_Update_3_QA\3_Working_GIS_Files\WP1\Land.shp": lyr.findAndReplaceWorkspacePath(r"M:\TEAM_GIS\EDKM\Projects\mmo1065_south_habitat_mapping\20140708_Update_3_QA\3_Working_GIS_Files\WP1", r"M:\TEAM_GIS\EDKM\Projects\mmo1065_south_habitat_mapping\20140708_Update_3_QA\3_Working_GIS_Files\SHP")arcpy.RefreshTOC()arcpy.RefreshActiveView()mxd.save()print "Success"

أكثر...
 
أعلى