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?

  • 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
    Commented Jul 7, 2011 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
    Commented Jul 7, 2011 at 19:18

2 Answers 2


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

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.

  • Have you verified that this actually fixes the paths to relative? Commented Jul 9, 2011 at 18:47
  • I have not tried it myself, no, but this thread suggests it should work: forums.esri.com/Thread.asp?c=93&f=1154&t=260812
    – blah238
    Commented Jul 9, 2011 at 21:04
  • Also I'm sure Kirk already knows how to do this: forums.esri.com/Thread.asp?c=93&f=992&t=64946 :)
    – blah238
    Commented Jul 9, 2011 at 21:08
  • @blah238 That's VBA, what I need is a standalone arcpy script. Commented Aug 23, 2011 at 14:00
  • 1
    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
    Commented Jan 26, 2012 at 18:19

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.