PYTHON GIS - Bulk convert mxd to a previous version

0

 


In this article you will learn how to convert (or save) all your MXD files to a previous version.



You will probably have the need to convert all MXD files used for graphical output or maps to a previous version of ArcGIS, either by client requirement or terms of reference.  


This is because each version of ArcMap saves files so that they can only be opened in an equal or higher version, thus encouraging users to constantly upgrade, but if the person or institution with whom you share your MXD files does not have an equal or higher version of ArcMap than yours you will need to save your files in an older version. The conventional way to do this is as described below:


How to save your MXD files to a previous version.


1) Open the MXD file to be saved in a previous version.


2) Go to file


Muestra la ubicación del botón File en el menú principal de ArcMap


3) Click “Save A Copy...” (a) in the displayed submenu.





 


4) Indicate where and with what name to save the file (Recommended to be in the same folder as the original file but with a different name, or in a folder inside the folder containing the original MXD files folder (See Notes). 


5) Specify the version in which the MXD file will be saved (a). Press the Save button (b).



6) Repeat this procedure for each MXD file.


With this you will have your ArcMap file saved in a previous version, but if there are many MXD files, it can be a titanic task. So I will show you how to do this in a much more efficient way using Python code (Don't worry, you won't need to program to do it). Follow the steps described below:


How to batch save MXD files to a previous version?


Step 0: Make a backup of the MXD.


Step 1: Identify the path where the MXD files to be converted are stored.  


Step 2: Open ArcMap.


Step 3: Open the Python window in the Standard toolbar.


Muestra la ubicación de la ventana Python dentro de la barra de herramientas Standard (estándar)


Step 4: Copy the following code into a notepad and replace the text C:\EJEMPLO\MXD_FOLDER in line #03 with the path to the folder identified in step 1. 



import arcpy, sys, os, string                                     #01
                                                                  #02
input_folder = r"C:\EJEMPLO\MXD_FOLDER"                           #03
output_folder = r"C:\EJEMPLO\CONVERTED_MXD_FOLDER"                #04
version = "10.0"                                                  #05
                                                                  #06
arcpy.env.workspace = input_folder                                #07
                                                                  #08
mxd_list = arcpy.ListFiles("*.mxd")                               #09
                                                                  #10
for mxd_file in mxd_list:                                         #11
    mxd_path = os.path.join(input_folder, mxd_file)               #12
    mxd = arcpy.mapping.MapDocument(mxd_path)                     #13
    output_file = os.path.join(output_folder,                     
    "{0}_{1}.mxd".format(os.path.splitext(mxd_file)[0], version)) #14
    mxd.saveACopy(output_file)                                    #15
    del mxd                                                       #16
                                                                  #17
del mxd_list                                                      #18


Step 5: Replace the text C:\EJEMPLO\CONVERTED_MXD_FOLDER in line #04 with the path to the folder where the files will be stored. The new folder must be located at the same subfolder level as the folder containing the original MXD files (see Notes).


Step 6: In line #05, replace the text 10.0 with the version you want to convert your MXD files to, it is only possible to convert to an older version than the one you have installed. The available options are as follows:  


  • 10.8: Version 10.8
  • 10.7: Version 10.7
  • 10.6: Version 10.6
  • 10.5: Version 10.5
  • 10.4: Version 10.4
  • 10.3: Version  10.3
  • 10.1: Version 10.1/10.2
  • 10.0: Version 10.0
  • 9.3: Version 9.3
  • 9.2: Version 9.2
  • 9.0: Version 9.0/9.1
  • 8.3: Version 8.3


Step 7: Copy the modified code into the Python window and press the Enter key twice.


After a few seconds you will see the MXD files begin to appear in the folder specified in step 5.


Notes:


For clarity, the path structure would be as follows:


Original folder -> C:\EJEMPLO\MXD_FOLDER

New folder -> C:\EJEMPLO\CONVERTED_MXD_FOLDER


As you can see both folders are inside the “EXAMPLE” folder and at the same subfolder level.


I hope you enjoyed this article, soon I will upload a video explaining the procedure that you can consult in this blog. Save my blog among your favorite links, I will be uploading many more tricks of this style, remember that you can send me your concerns in the contact page or leave your comment, I will be attentive to respond.

You may like these posts

No comments