top of page

FIXING BROKEN .MXD CONNECTIONS WITH PYTHON

A common problem encountered by those working in the GIS field is when you have an .mxd (an Arc file) or multiple .mxds that has its layer connections broken. This occurs when the data source for a layer is moved to a different location in directories or servers. It takes a substantial amount of time to open .mxds individually and fix these broken connections by hand, so I created a Python script that will do it all for me.

GEOG 6180 - Geoprocessing with Python

GEOG 6180: Text

Methods and Data Sources

  • In the script below, env.workspace establishes the location of the .mxds.

  • Used arcpy.mapping.MapDocument to designate the .mxd that is going to have its connections fixed with the script.

  • The function MapDocument.findAndReplaceWorkspacePaths was used in the script. This tool takes the whole .mxd and is able to fix every layer’s broken connection. It designates the original file path for the data, and then designates the new one.

  • Finally, MapDocument.saveACopy was used to save a copy of the map with its connections fixed. Wrote a new name for the document in the file path.

  • The data used in the script was sample data that contained multiple feature classes that could be manipulated easily. 

6180 Image.png

Figure 1: Python Script

GEOG 6180: Image

.Mxd Connections Before (left) and After (right) the Script

Figure 2: Connections Before and After the Script

GEOG 6180: Image

Conclusion

The script can now be used any .mxd connections that are broken through the movement of data. It requires little modification to fit any directory, and vastly reduces the amount of time required to reconnect layers to its data. Additional code can be added to the script to fix just a single layer with a broken connection, or if the data was not all moved to the same location in the directory.

GEOG 6180: Text

Skills Learned / Used

  • GIS Workflow

  • Programming and Scripting

GEOG 6180: Text
bottom of page