I'm using ArcGIS 10.0 and arcpy.mapping.ListLayers to iterate through the layers in a list of MXDs. my problem is that someon has saved a 10.1 mxd somewhere in the list of MXDs I'm working through. I'd be fine with just skipping that file, but how do I determine what version a MXD file is from Python?
for mxdPath in mxdList: try: mxd = arcpy.mapping.MapDocument(mxdPath) ## < do your stuff > except: print "Could not open the map document: \"%s\"" % mxdPath
import arcpy pathList =  pathList.append(r"\\server\share\MyVersion10.mxd") pathList.append(r"\\server\share\MyVersion10_1.mxd") for eachPath in pathList: try: MXD = arcpy.mapping.MapDocument(eachPath) for lyr in arcpy.mapping.ListLayers(MXD): print(lyr.name) except: print("failed on " + eachPath)
As you describe, it makes connection to the 10.1 MXD just fine, it's once you try to list the layers that the script crashes.
There has to be some way to determine if the MXD you are connected to is valid that will at least respect the "try" block instead of completely bombing python.