ArcPy method to determine ArcMap document version
I want to be able to identify ArcMap documents by the folder using PythonWin.
When using Ryan's script (link above) I ran into some kind of problem. It runs without error, but could not determine the version of any of them. The versions range of the documents I have are from ArcGIS 9.3 through 10.5. Without an error I'm not sure why the versions aren't being recognized?
-
Are you using ArcPy? If so, what version of ArcGIS Desktop are you using?PolyGeo– PolyGeo ♦2017年06月16日 20:25:46 +00:00Commented Jun 16, 2017 at 20:25
-
1@Midavalo good point - I wonder if the asker has tried both solutions there. It seems odd that they both have lots of votes, a few doubts about whether they work post-10.3, and this asker saying they don't work at any tested version. I think we need more details about precisely what the user has tested.PolyGeo– PolyGeo ♦2017年06月16日 20:34:52 +00:00Commented Jun 16, 2017 at 20:34
-
1I did a quick copy/paste (and point at the correct folder) - the script works for me on 10.5. I had to add 10.4 and 10.5. Of the 5 MXDs in my folder it identified 4 (3 as 10.5, 1 as 10.4). I'm not sure which version the unidentified one is.Midavalo– Midavalo ♦2017年06月16日 21:55:11 +00:00Commented Jun 16, 2017 at 21:55
-
1And the second answer on the linked Q&A worked great and identified all files.Midavalo– Midavalo ♦2017年06月16日 22:00:29 +00:00Commented Jun 16, 2017 at 22:00
-
2@Midavalo I'm thinking that this question should end up as a merged duplicate of the original so that all the answers are in one place.PolyGeo– PolyGeo ♦2017年06月16日 22:48:05 +00:00Commented Jun 16, 2017 at 22:48
1 Answer 1
Try using the script from the second answer in your linked Q&A.
I created a folder with MXDs from almost every version between 8.3 and 10.5.
I had varied success using the script from the first answer, but much better success using the script from the second answer. Every version was recoginised except 9.3. I'm unsure why yet, I'm still digging.
import glob, os, sys
from oletools.thirdparty import olefile
def mxd_version(filename):
ofile = olefile.OleFileIO(filename)
stream = ofile.openstream('Version')
data = stream.read().decode('utf-16')
version = data.split('\x00')[1]
return version
folder = r'C:\GIS\SE\TestMXDVersions'
mxdFiles = glob.glob(os.path.join(folder, '*.mxd'))
for mxdFile in mxdFiles:
fileName = os.path.basename(mxdFile)
print mxdFile, (mxd_version(mxdFile))
C:\GIS\SE\TestMXDVersions\x100.mxd 10.0
C:\GIS\SE\TestMXDVersions\x101.mxd 10.1
C:\GIS\SE\TestMXDVersions\x103.mxd 10.3
C:\GIS\SE\TestMXDVersions\x104.mxd 10.4
C:\GIS\SE\TestMXDVersions\x105.mxd 10.5
C:\GIS\SE\TestMXDVersions\x83.mxd 8.3
C:\GIS\SE\TestMXDVersions\x90.mxd 9.0
C:\GIS\SE\TestMXDVersions\x92.mxd 9.2
C:\GIS\SE\TestMXDVersions\x93.mxd An unexpected error occured while printing the document.
-
Thanks all for the help. I'm using PythonWin 2.7, not ArcPy. Yes, I have tried the second option of the link. But it requires the oletools module and the organisation I'm working for might have a problem with downloading it. But, I'm willing to try anyway since the first option can't determine any of my MXDs, which I know range from 9.2 - 10.4 (I used their exact script and pointed to my own test folder). @Midavalo -Can I ask what form of Python you're using and how you brought in oletools? I used the link from further down in the liked Q&A to download the oletools 0.50, but am confusedPfalbaum– Pfalbaum2017年06月19日 14:30:04 +00:00Commented Jun 19, 2017 at 14:30
-
@Pfalbaum I am using Python 2.7 on ArcGIS 10.5. I am not using Pythonwin but that shouldn't make any difference in how the script runs. I use Microsoft Visual Studio with Python Tools for VS installed - this has PIP integrated so installing OleTools was a simple search and click to install. You may be able to just use the PIP command on your computer to download and install OleTools. See Installing Python Modules.2017年06月19日 14:46:08 +00:00Commented Jun 19, 2017 at 14:46
-
1You're right, it ran using Pythonwin. I installed the module using the Readme directions (novice alert*) in the folder, and then ran setup.py (setting the correct file paths to the oletools-0.50 folder). After that, I put MXDs in a test folder from 9.0 - 10.4 and the script was successful in identifying all of them.Pfalbaum– Pfalbaum2017年06月19日 17:35:40 +00:00Commented Jun 19, 2017 at 17:35
-
@Midavalo, unbelievably good :) did it take you a long time to figure out what methods to use in the
oletools
package to read the needed parts of.mxd
? Do you know any published docs on this except some GIS.SE question?Alex Tereshenkov– Alex Tereshenkov2017年07月29日 06:16:55 +00:00Commented Jul 29, 2017 at 6:16