2

I'm running a script (ArcMap 10.5) that loops through a list of mxds, and saves a copy with a new name showing the year and quarter. This works for all mxds, unless they have an annotation feature class in them.

When there is an annotation featureclass, I get this error:

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.

The script is very simple.

mapList = [r"C:\Projects\Figure 1.mxd", r"Z:\Projects\Figure 2.mxd"]               

#make updates
for mapDoc in mapList:
    mxd = arcpy.mapping.MapDocument(mapDoc)

    #generate year and quarter
    some code...
    Q_Y = "Q" + quarter + " " + year

    #generate names/paths
    bn = os.path.basename(mapDoc).replace(".mxd", "") + " " + Q_Y
    #path
    fullPathMXD = os.path.join(C:\Projects, bn + ".mxd")

    #save as new map doc
    mxd.saveACopy(fullPathMXD)

    #create new map doc object to export EPS from
    mxd2 = arcpy.mapping.MapDocument(fullPathMXD)

    #update title/eps name
    mxd2.title = ....

    #export to eps
    arcpy.mapping.ExportToEPS(mxd2, locationPDF + "\\" + bn + ".eps",
                              "Page_Layout",640,480,200,"BEST","RGB",3,
                              "ADAPTIVE","RASTERIZE_BITMAP",True,False)

Has anyone encountered this problem, or can anyone tell me what's going on here?

The mxds that do not throw this error do not have annotation featureclasses, but do have featureclasses that live in the same .gdb.

UPDATE

I used disutils to copy the mxd to a new location, under a different name, and this solved the first error. However, it now throws this error:

AttributeError: 'NoneType' object has no attribute 'exportToEPS'

Again, this only happens when there are annotation layers in the map. Without them, the original, and the "disutils", version work as expected.

  • What version of ArcGIS are you using? – Hornbydd Sep 20 '17 at 20:02
  • Just an idea, saveACopy() also takes a version number parameter, try setting that? – Hornbydd Sep 20 '17 at 20:04
  • I'm using 10.5, just edited the post to reflect that, thanks. I'll check out the version number parameter. – CSB Sep 20 '17 at 20:18
  • Hornbydd - changing the version parameter gives the same result. – CSB Sep 21 '17 at 15:09
  • 1
    If you are not changing anything inside the mxd that needs persisting maybe you can rewrite your code to copy the file using standard file management modules like os rather than using arcpy to make the copy? You could copy it then open it's new location then run your Export to EPS? – Hornbydd Sep 21 '17 at 15:51
1

The problem turned out being differing versions of ArcMap that my python shell was using (10.3), and the .mxd I was trying to work with was using (10.5). However, there was no issue as long as there was no annotation layer involved. I am now running this script from within a .mxd only. Problem solved (well, avoided anyway).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.