I have an .mxd with broken link layers and each layer has a different new path. I know the python script for repairing the broken links of the layers, but I want to put all the new paths of the layers and then let python do and finish all the process. The script that I have does it one at a time. I know if all the shapefiles are in one path then it's done by performing it once. but what if they al have different paths?
To clarify, let's say I have 3 layers with broken links and each one has a different new path now. I'd like to have a GUI with 3 inputs for the new paths altogether or let script do the process one by one and each time asking for the next path to input.
Answer
Unfortunately the GUI by itself doesn't know how many broken layers you have, the easiest way to do this might be through the Python promt with a script similar to the following (See the Layer Class documentation for more on the replaceDataSource method):
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.ListBrokenDataSources(mxd):
print "Datasource %s does not exist" % lyr.dataSource
workspace_path = raw_input("New Workspace: ")
workspace_type = raw_input("Workspace type: ") #See http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/
dataset_name = raw_input("Dataset name (enter for %s): " % lyr.datasetName)
if len(dataset_name) == 0:
dataset_name = lyr.datasetName
#Note, there's no error checking above, so we set validate to True
arcpy.mapping.replaceDataSource(workspace_path, workspace_type, dataset_name, True)
#mxd.save() #uncomment if you want changes saved when the script finishes
No comments:
Post a Comment