Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Can you show us what code you have now? – Chad Cooper Jan 9 '12 at 13:03
up vote 4 down vote accepted

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
    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) #uncomment if you want changes saved when the script finishes
share|improve this answer
Thanks for your prompt response. Here's my code which does almost the same: import arcpy mapDoc=arcpy.mapping.MapDocument("Current") brokenLayer=arcpy.mapping.ListBrokenDataSources(mapDoc)[0] path=arcpy.GetParameterAsText(0) brokenLayer.replaceDataSource(path) arcpy.RefreshTOC() but every time, you have to invoke this script and input a new path. what I'm looking for is like creating maybe a loop according to the number of broken links that each one has a different path. – Matt Jan 9 '12 at 17:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.