5

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.

1
  • 1
    Can you show us what code you have now? Commented Jan 9, 2012 at 13:03

1 Answer 1

5

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
1
  • 1
    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.
    – Mehdi
    Commented Jan 9, 2012 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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