Wednesday, 3 August 2016

python - Batch convert ArcGIS 9x files to 10



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"

Answer



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 _10.mxd. Though, again, you don't need this. You could also replace the saveACopy line with .save() and just replace each MXD.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...