import arcpy import arcpy.mapping as map mxd = map.MapDocument(r"C:\MGIS\Finalproject2.mxd") mxd.saveACopy(mxd)
Traceback (most recent call last): File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 312, in RunScript exec codeObject in __main__.__dict__ File "C:\MGIS\geog485\FinalProject2\mxdtest.py", line 7, in <module> mxd.saveACopy(mxd) File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\_mapping.py", line 668, 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.
import arcpy import arcpy.mapping as map mxd = map.MapDocument(r"C:\MGIS\Finalproject2.mxd") mxd.saveACopy(r"c:\MGIS\FINALPROJECT3.mxd")
mxd = map.MapDocument(arcpy.GetParameterAsText(0)) #r"C:\MGIS\Finalproject2.mxd" as the parameter in the script tool
mxd1 = arcpy.GetParameterAsText(1) #r"C:\MGIS\Finalproject2mxd1.mxd" as the parameter in the script tool mxd.saveACopy(mxd1)
env.workspace = r"C:\fp2.gdb"
arcpy.AddField_management ("dec209data", "dec2009dataLayer")
import os #... code workPath = os.path.dirname(env.workspace) print workPath # do stuff del workPath
I didn't include it in the code I posted originally (my script is pretty long), but I already have env.workspace defined as a gdb file path (actually it's not hardcoded, I'm using arcpy.GetParameterAsText since I am also creating a script tool).env.workspace = r"C:\fp2.gdb"
so that I don't have to define like 5 more variables when I need to call them further down in my script and can just use "":
ex.arcpy.AddField_management ("dec209data", "dec2009dataLayer")
The problem is that you cannot save an .mxd into a gdb so the location of my mxd is not within the env.workspace (it's in the same folder as the .gdb though - C:\fp2copy). So I believe this is why it will not overwrite the mxd and I have to define another variable for an mxd if I want to be able to save the 4 layers that I am adding to it using arcpy.mapping module (as in my previous post using mxd1).
Correct me if I am wrong, but the only way I would be able to overwrite my mxd is to change the env.workspace to the folder I am processing everything to/from (C:\fp2copy) and then define variables for all of the datasets currently being saved within the gdb (see attached) or will one of the other methods you suggested work (os module etc.)? I'm trying to create the least amount of variables as possible for efficiency.
Thanks so much for your assistance!!
You can't save an mxd inside a file geodatabase, you need to save it in a folder.
To get the path of your workspace, try this:import os #... code workPath = os.path.dirname(env.workspace) print workPath # do stuff del workPath
arcpy.env.overwriteOutput = True
This is just a simple thought, but...
Make sure that you do not have the script open in your IDE when you are trying to run in ArcMap and the other way around. This will cause locking/permissions problems like what you are seeing