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 a large number of project folders where each project folder can have many subfolders. These subfolders can contain mxds, shapefiles, personal gdb's and fgdb's. In many cases the user forgot to check the "Use Relative Paths" before saving the mxds, so when the folder gets copied, datasource links become broken.

I would like to write a standalone arcpy script that crawls through the directories, opens each mxd, sets the relativePaths to true, then saves the mxd. Is there a script that does this somewhere?

The relativePaths property on the MapDocument object is readonly. Is there some other way to change this?

share|improve this question
I am unsure of this is possible or not using that workflow. But what I do think could work is if you automatically open each .mxd, copy all data sources and information from that original .mxd into a new blank .mxd that has relative paths checked, and then re-save the new one. Just an idea as a work-around if your first way ends up not being possible. – MLowry Jul 7 '11 at 18:14
I don't think it's possible. You could get a list of all documents using absolute paths and their authors and SPAM them with a stern e-mail, though. – Sean Jul 7 '11 at 19:18

This is possible using the following python script (with thanks to Neil Clemmons over at the ESRI forum). You will need the comtypes library and the Snippets module from Pierssen Consulting.

from Snippets import GetLibPath, InitStandalone
from comtypes.client import GetModule, CreateObject
import os

m = GetModule(GetLibPath() + 'esriCarto.olb')
file_dir = r'C:\dir'
for filename in os.listdir(file_dir):
   fullpath = os.path.join(file_dir, filename)
   p = CreateObject(m.MapDocument, interface=m.MapDocument)
   newpath = os.path.join(file_dir,'Changed_' + filename)
   del p
share|improve this answer
Also see the local canonical thread for using Pierssen's Snippets module at How do I access ArcObjects from Python? – matt wilkie Jan 6 '15 at 21:58

Not possible in 10.0, but I have had some success using ArcObjects in Python for relatively simple tasks like this where writing a .NET application would be overkill, but the necessary functionality was not exposed in the arcpy/arcgisscripting modules. Use os.walk for the crawling the directory tree part.

For the ArcObjects bit, use IMapDocument.Open() to open the MXD (without having to have it open in ArcMap), cast to IMxDocument and set RelativePaths to true, and use IMapDocument.Save() to save it.

share|improve this answer
Have you verified that this actually fixes the paths to relative? – Jason Scheirer Jul 9 '11 at 18:47
I have not tried it myself, no, but this thread suggests it should work: – blah238 Jul 9 '11 at 21:04
Also I'm sure Kirk already knows how to do this: :) – blah238 Jul 9 '11 at 21:08
@blah238 That's VBA, what I need is a standalone arcpy script. – Kirk Kuykendall Aug 23 '11 at 14:00
The question was in reference to doing this with arcpy, not .NET, and as I understand it's not possible to do with arcpy at 10.0 (see the first link in my answer). – blah238 Jan 26 '12 at 18:19

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.