ArcPy, Determine what version an MXD is?

9377
12
Jump to solution
08-02-2010 02:19 PM
RandyKreuziger
Occasional Contributor III
I have an ArcPy python script that replaces data sources.  Right now I'm saving out the MXDs as 9.3
but ideally I want to save the repaired version out in the same version of ArcGIS that the original is in.  Is there a way to do this? 

If I don't specify the version my 9.3 mxds are saved out in version 10.
0 Kudos
1 Solution

Accepted Solutions
WilliamCraft
MVP Regular Contributor

I know this is an old thread, but here is some code I wrote to do the trick.  It can be incorporated into a loop for multiple MXDs.  

import os, sys, arcpy, re
mxdFile = "C:\\temp\\map_document.mxd"
mxd101 = '10.1' + u'\u0013'
mxd102 = '10.1' + u'\u0013'
mxd103 = '10.3' + u'\u0014'
mxd104 = '10.4' + u'\u0015'
mxd105 = '10.5' + u'\u0016'
mxd106 = '10.6' + u'\u0017'
mxdList = [mxd101, mxd102, mxd103, mxd104, mxd105, mxd106]
result = []
with open(mxdFile, 'rb') as mxd:
   fileContents = mxd.read().decode('latin1')
   removedChars = [x for x in fileContents if x not in [u'\xff',u'\x00',u'\x01',u'\t']]
   joinedChars = ''.join(removedChars)
   for m in mxdList:
   location = joinedChars.find(m)
   if len(joinedChars[location:location+4]) > 0:
   result.append(joinedChars[location:location+4])
   print result[0]‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

12 Replies
DavidWynne
Esri Contributor
Hi kreuzrsk,
Yes, you can save out a map document to a different version using the saveACopy method on the MapDocument class.  The last argument is a version keyword.

>>> mxd.saveACopy("c:/output/base_93.mxd", "9.3")


http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/MapDocument/00s30000000n000000/

-Dave
0 Kudos
RandyKreuziger
Occasional Contributor III
Thanks but I know that already.  I need to save the MXD out to the same version of ArcGIS.  So if it's 9.3 I want to save to 9.3 but if it is 9.2 it needs to be saved as 9.2.  I notice that if you leave out the version keyword it upgrades the MXD to 10.0.
0 Kudos
DavidWynne
Esri Contributor
Thanks but I know that already.  I need to save the MXD out to the same version of ArcGIS.  So if it's 9.3 I want to save to 9.3 but if it is 9.2 it needs to be saved as 9.2.  I notice that if you leave out the version keyword it upgrades the MXD to 10.0.


No, not possible in Python in ArcGIS 10 to tell what release a mapdocument is currently saved as (I'm told possibly at 10.1)
-Dave
0 Kudos
LinkElmore
New Contributor III
Is is possible to determine .mxd version from within ArcMap itself?  It's not listed in Map Document Properties (I'm using v10.0), where I thought it should be.
0 Kudos
RandyKreuziger
Occasional Contributor III
No, not possible in Python in ArcGIS 10 to tell what release a mapdocument is currently saved as (I'm told possibly at 10.1)
-Dave


Dave,
  Assuming you're still out there do you know if this got added to 10.1?  I really need that able in a script I'm writing that strips out broken map service datasources. 

Thanks
0 Kudos
MichaelVolz
Esteemed Contributor
Can anyone from ESRI answer this question?

I am currently running a similar script in v10.0 where it is not possible.  Once this script has processed all my organization's mxds and lyr files, I will be upgrading my enterprise GIS environment to v10.2.  I will need to run this script again in the v10.2 environment when my organization upgrades our SDE Oracle database from 11g to 12c, so this capability would be useful if it is now available at v10.2.
0 Kudos
DavidWynne
Esri Contributor
Dave,
  Assuming you're still out there do you know if this got added to 10.1?  I really need that able in a script I'm writing that strips out broken map service datasources. 

Thanks


Alas, no. 

I did see this strategy listed under the answer section that seems to hold though: http://gis.stackexchange.com/questions/62090/arcpy-method-to-determine-arcmap-document-version
MikeMacRae
Occasional Contributor III
Alas, no. 

I did see this strategy listed under the answer section that seems to hold though: http://gis.stackexchange.com/questions/62090/arcpy-method-to-determine-arcmap-document-version


That's a very clever solution. Very useful!
0 Kudos
WilliamCraft
MVP Regular Contributor

I know this is an old thread, but here is some code I wrote to do the trick.  It can be incorporated into a loop for multiple MXDs.  

import os, sys, arcpy, re
mxdFile = "C:\\temp\\map_document.mxd"
mxd101 = '10.1' + u'\u0013'
mxd102 = '10.1' + u'\u0013'
mxd103 = '10.3' + u'\u0014'
mxd104 = '10.4' + u'\u0015'
mxd105 = '10.5' + u'\u0016'
mxd106 = '10.6' + u'\u0017'
mxdList = [mxd101, mxd102, mxd103, mxd104, mxd105, mxd106]
result = []
with open(mxdFile, 'rb') as mxd:
   fileContents = mxd.read().decode('latin1')
   removedChars = [x for x in fileContents if x not in [u'\xff',u'\x00',u'\x01',u'\t']]
   joinedChars = ''.join(removedChars)
   for m in mxdList:
   location = joinedChars.find(m)
   if len(joinedChars[location:location+4]) > 0:
   result.append(joinedChars[location:location+4])
   print result[0]‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍