Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 2 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 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
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
add comment

Your Answer

 
discard

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.