2

I would like to convert all mxd's in a directory and it's subdirectories to ArcGIS 10 mxd's. This is so that I can then run python to automate some updates within them.

Is this possible?

This is my second post and I was also wondering if I should post sample code?

=== UPDATE -- Here's the code (for more usefully) converting 10 files to 9.3

#Downgrades all ver 10 mxds in directory and subdirectories to version 9.3
#and saves them with _93 extension.


import arcpy, glob, os

path = os.getcwd()
for pathname, directories, filenames in os.walk(path):
    for filename in filenames:
        if filename.lower().endswith(".mxd"):
            mxd = arcpy.mapping.MapDocument(os.path.join(pathname, filename))
            filename, ext = os.path.splitext(os.path.join(pathname, filename))
            if mxd.dateSaved:
                    print mxd.dateSaved
                    mxd.saveACopy(filename + "_93" + ext, "9.3")
                    currentMxd = filename + "_93" + ext
                    mapDoc=arcpy.mapping.MapDocument(currentMxd)
                    print "Updated: " + filename
            else:
                    print filename + "is not version 10 therefore not altered"
1
  • Yes, posting sample code is often helpful. Commented May 11, 2011 at 23:02

3 Answers 3

12

Previous MXDs should load, no need for conversion. However, it will save to 10.0 when you save your updates.

However:

import arcpy
import glob
import os

for pathname, directories, filenames in os.walk(r"c:\startdir"):
    for filename in filenames:
        if filename.lower().endswith(".mxd"):
            mxd = arcpy.mapping.MapDocument(os.path.join(pathname, filename))
            filename, ext = os.path.splitext(os.path.join(pathname, filename))
            mxd.saveACopy(filename + "_10" + ext)

This will save a duplicate copy of each .mxd as a 10.0 MXD under the name <filename>_10.mxd. Though, again, you don't need this. You could also replace the saveACopy line with .save() and just replace each MXD.

1
  • Thanks Jason. I was under the impression that python needed files in 10 version to extract dataframe names, scales etc. Is this not correct? Can i use this to convert from 10x to 9x?
    – GeorgeC
    Commented May 12, 2011 at 0:08
2

Please be aware that there is a bug in arcpy.mapping that will not include any metadata stored in the Map Document Properties when you upgrade a map (in fact, arcpy.mapping doesn't have access to 9.x mxd metadata at all, regardless of whether you're trying to upgrade the mxd).

I was attempting to automate the addition of metadata to our legacy mxds for use with Arc 10's new indexing functionality and ran into this issue. If you load an older mxd in ArcMap and resave it as an Arc10 document the metadata is maintained. But if you load it via arcpy.mapping, the metadata is missing.

esri is aware of the issue and has assigned it bug report number NIM068837

1

I'm using ArcGis10 sp3. The tool seemed to work, but it was very very slow.

So I suggest to import the tool into arcmap (for example in the toolbox, or just copy/paste it in your arcpy window) and run it. This way it will work like a charm :)

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.