Select to view content in your preferred language

findAndReplaceWorkspacePaths function Fails On Empty MXDs

601
2
07-29-2013 04:39 AM
EricMahaffey
Deactivated User
I know, I know who would want to repair the datasources on an MXD that has not layers in it.  Technically not me, however, I was tasked to help some people who have created several empty files amongst a whole mess of other ones in various folders.  My Python script runs just fine until it come across an MXD with no data layers, then it errors out saying:

Traceback (most recent call last):
  File "D:/Users/Tools/Repair Data Sources/Scripts/repair_mxd_sources_production_2.py", line 45, in <module>
    outputMXDname = newmxdname.saveACopy(root + "\\" + inputmxdname.strip(".mxd") + "_Source_Repaired.mxd")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_
    return fn(*args, **kw)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\_mapping.py", line 828, in saveACopy
    self._arc_object.saveACopy(file_name)
AttributeError: MapDocObject: Unable to save.  Check to make sure you have write access to the specified file and that there is enough space on the storage device to hold your document.


Not sure why it's having an issue saving an empty file.  Is there any way to get it to ignore MXDs with no data?  Maybe even ignore ones that have a file size of 5KB or below?
0 Kudos
2 Replies
JimCousins
MVP Alum
Use a Try... Except statement. This allows you to handle exceptions, like not having any layers to findAndReplaceWorkspacePaths on. Using this will allow you to continue on past the empty map documents.
0 Kudos
EricMahaffey
Deactivated User
Thanks Jim.  The try/catch worked just fine.  The script is running as I type.  Have a good one.
0 Kudos