ArcPy mapping - MapDocObject: Unable to save Attribute Error

3735
5
Jump to solution
05-07-2013 08:08 PM
StephenPage
New Contributor
I???m running a script to update the SDE Connection file path. This works fine. But I???m getting an output error ??? SOMETIMES!

The error occurs at the Save Map statement:

File "c:\program files\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.


I have no Arcmap or ArcCat open.

Here???s my script:

import arcpy, os  # INPUT PARAMETERS Input_mxd = "G:\GIS\Weave\mxd\REBUILD\DataSrceTesting_2LblLayers_PptySbrbs.mxd" Output_mxd = "G:\GIS\Weave\mxd\REBUILD\newDataSource_EmptyOutput_3.mxd" Input_SDE = "Database Connections\Connection to vgeodb.sde" Output_SDE = "G:\GIS\Weave\Connections\Connection to 10.1.4.127.sde"  mxd = arcpy.mapping.MapDocument(Input_mxd) for lyr in arcpy.mapping.ListLayers (mxd):  mxd.findAndReplaceWorkspacePaths(Input_SDE, Output_SDE)  print lyr  print lyr.dataSource mxd.saveACopy(Output_mxd)


The print statements are just so I can see whats going on - the code appears to update the connection paths as required.

Thanks
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor
The shutil error maybe occurring because you have not imported the module?  You would need to put it at the top of your script.

import shutil


But looking at your code I notice you have not put an "r" in front of your strings.

You want your code to look like:

Output_mxd = r"G:\GIS\Weave\mxd\REBUILD\newDataSource_EmptyOutput_3.mxd"

View solution in original post

0 Kudos
5 Replies
StephenPage
New Contributor
I (belatedly) found a thread "1. MapDocument.saveACopy() Error " from 5 May, which has some solutions in it.

I've tried these but can't get them  to work
i) the saveACopy statement still throws the "can't save" error

ii) the shutil.copy2(inputMxd, old_doc) statement says:

NameError: name 'shutil' is not defined

Thanks
0 Kudos
DuncanHornby
MVP Notable Contributor
The shutil error maybe occurring because you have not imported the module?  You would need to put it at the top of your script.

import shutil


But looking at your code I notice you have not put an "r" in front of your strings.

You want your code to look like:

Output_mxd = r"G:\GIS\Weave\mxd\REBUILD\newDataSource_EmptyOutput_3.mxd"
0 Kudos
StephenPage
New Contributor
Thanks for your reply which WAS appreciated very much (and solved my issue), and humble apologies for completely overlooking to respond!

Is perhaps putting an "r" in front of strings new to Arcpython under version 10? I don't recall this from 9.3, and it doesn't seem to be in my sample scripts from then.

Perhaps I need a refresher to update myself to the latest code!

Similarly, I haven't struck the 'shutil' module before, but my 9.3 copy methods don't seem to work. Couldn't get this to workk yet either - so I just manually copied the file - but I'll get back to that when there's time!

Thanks again

Steve
0 Kudos
JamesCrandall
MVP Frequent Contributor


Is perhaps putting an "r" in front of strings new to Arcpython under version 10? I don't recall this from 9.3, and it doesn't seem to be in my sample scripts from then.



Steve,

From a quick look at some examples, the "r" in front of a quoted string indicates a string literal -- for example any escape characters will not be evaluated.  So,


print r'testing \n'



Would print the entire quoted string "testing \n"


print 'testing \n'



Would print "testing" and a newline space.
0 Kudos
StephenPage
New Contributor
Thanks James
0 Kudos