<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: error with mxd.save/mxd.SaveACopy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340317#M26708</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can't save an mxd inside a file geodatabase, you need to save it in a folder.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To get the path of your workspace, try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import os

#... code
workPath = os.path.dirname(env.workspace)
print workPath
# do stuff
del workPath
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;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).&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;env.workspace = r"C:\fp2.gdb"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;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 "":&lt;BR /&gt;&lt;BR /&gt;ex.&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.AddField_management ("dec209data", "dec2009dataLayer")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;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).&amp;nbsp; 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).&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;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.)?&amp;nbsp; I'm trying to create the least amount of variables as possible for efficiency.&lt;BR /&gt;&lt;BR /&gt;Thanks so much for your assistance!!&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 16:06:09 GMT</pubDate>
    <dc:creator>AndrewChapkowski</dc:creator>
    <dc:date>2021-12-11T16:06:09Z</dc:date>
    <item>
      <title>error with mxd.save/mxd.SaveACopy</title>
      <link>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340310#M26701</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to use arcpy to save an .mxd and am having an issue. It doesn't matter if I use mxd.save or mxd.saveACopy I get the same error. I know it doesn't look like I am doing anything w/ it here, but it's just a portion of my code that I've pulled out into a separate script to test:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
import arcpy.mapping as map

mxd = map.MapDocument(r"C:\MGIS\Finalproject2.mxd")
mxd.saveACopy(mxd)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Traceback (most recent call last):
&amp;nbsp; File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 312, in RunScript
&amp;nbsp;&amp;nbsp;&amp;nbsp; exec codeObject in __main__.__dict__
&amp;nbsp; File "C:\MGIS\geog485\FinalProject2\mxdtest.py", line 7, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.saveACopy(mxd)
&amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_
&amp;nbsp;&amp;nbsp;&amp;nbsp; return fn(*args, **kw)
&amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\_mapping.py", line 668, in saveACopy
&amp;nbsp;&amp;nbsp;&amp;nbsp; self._arc_object.saveACopy(file_name)
AttributeError: MapDocObject: Unable to save.&amp;nbsp; 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.&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Space is not the issue, I have 60 GB of free space and I've checked the windows properties of the .mxd file. Read-only box is unchecked and I've "allowed" all permissions for all groups:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]13339[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone have any idea how if this is a bug or how I can fix this?&amp;nbsp; It's probably user error but is really holding me up. I'm using PythonWin 2.6 ArcInfo 10.0 SP4.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Apr 2012 14:18:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340310#M26701</guid>
      <dc:creator>Michele</dc:creator>
      <dc:date>2012-04-09T14:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: error with mxd.save/mxd.SaveACopy</title>
      <link>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340311#M26702</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You need to pass a path to the function, not the MapDocument object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import arcpy
import arcpy.mapping as map

mxd = map.MapDocument(r"C:\MGIS\Finalproject2.mxd")
mxd.saveACopy(r"c:\MGIS\FINALPROJECT3.mxd")

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s30000000n000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s30000000n000000&lt;/A&gt;&lt;SPAN&gt; for more information.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:06:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340311#M26702</guid>
      <dc:creator>AndrewChapkowski</dc:creator>
      <dc:date>2021-12-11T16:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: error with mxd.save/mxd.SaveACopy</title>
      <link>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340312#M26703</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for the reply Andrew.&amp;nbsp; So say I want to make a script tool and will need the mxd variable in the following format:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd = map.MapDocument(arcpy.GetParameterAsText(0)) #r"C:\MGIS\Finalproject2.mxd" as the parameter in the script tool&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;would I then need to define another variable, say mxd1 for the save:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd1 = arcpy.GetParameterAsText(1) #r"C:\MGIS\Finalproject2mxd1.mxd" as the parameter in the script tool
mxd.saveACopy(mxd1)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or is there a more efficient way of doing this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:06:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340312#M26703</guid>
      <dc:creator>Michele</dc:creator>
      <dc:date>2021-12-11T16:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: error with mxd.save/mxd.SaveACopy</title>
      <link>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340313#M26704</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;For your first variable, if you input is a string, then yes you could do it that way.&amp;nbsp; There is also an input called ArcMap Document that you might want to look at.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For the 2nd parameter, assuming it's of type string, then yes that's how it would work.&amp;nbsp; I would also perform some checks to ensure that the input is a valid format of .mxd, and that the file you are going to write to does not exist.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Apr 2012 09:21:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340313#M26704</guid>
      <dc:creator>AndrewChapkowski</dc:creator>
      <dc:date>2012-04-10T09:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: error with mxd.save/mxd.SaveACopy</title>
      <link>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340314#M26705</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just for clarification...there isn't a way to overwrite an .mxd using arcpy? I have to use 2 variables??&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Apr 2012 21:44:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340314#M26705</guid>
      <dc:creator>Michele</dc:creator>
      <dc:date>2012-04-10T21:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: error with mxd.save/mxd.SaveACopy</title>
      <link>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340315#M26706</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sure you can overwrite a map document.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd set the environmental overwrite output parameter to true.&amp;nbsp; If you are currently accessing the map document, I'd use save().&amp;nbsp; That will save any changes in the current map document.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to export changes to say an existing file, you can use either standard python like the shutil or os module to copy and remove files, or you can use the arcpy Delete() and Copy() in the data management toolbox. You can also try just using the SaveAs() function on the MapDocument object with the overwrite output parameter set to true.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Apr 2012 09:12:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340315#M26706</guid>
      <dc:creator>AndrewChapkowski</dc:creator>
      <dc:date>2012-04-11T09:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: error with mxd.save/mxd.SaveACopy</title>
      <link>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340316#M26707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;env.workspace = r"C:\fp2.gdb"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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 "":&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ex.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.AddField_management ("dec209data", "dec2009dataLayer")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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).&amp;nbsp; 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).&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.)?&amp;nbsp; I'm trying to create the least amount of variables as possible for efficiency.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks so much for your assistance!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Apr 2012 17:21:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340316#M26707</guid>
      <dc:creator>Michele</dc:creator>
      <dc:date>2012-04-11T17:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: error with mxd.save/mxd.SaveACopy</title>
      <link>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340317#M26708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can't save an mxd inside a file geodatabase, you need to save it in a folder.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To get the path of your workspace, try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import os

#... code
workPath = os.path.dirname(env.workspace)
print workPath
# do stuff
del workPath
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;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).&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;env.workspace = r"C:\fp2.gdb"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;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 "":&lt;BR /&gt;&lt;BR /&gt;ex.&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.AddField_management ("dec209data", "dec2009dataLayer")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;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).&amp;nbsp; 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).&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;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.)?&amp;nbsp; I'm trying to create the least amount of variables as possible for efficiency.&lt;BR /&gt;&lt;BR /&gt;Thanks so much for your assistance!!&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:06:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340317#M26708</guid>
      <dc:creator>AndrewChapkowski</dc:creator>
      <dc:date>2021-12-11T16:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: error with mxd.save/mxd.SaveACopy</title>
      <link>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340318#M26709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You can't save an mxd inside a file geodatabase, you need to save it in a folder.&lt;BR /&gt;&lt;BR /&gt;To get the path of your workspace, try this:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import os

#... code
workPath = os.path.dirname(env.workspace)
print workPath
# do stuff
del workPath
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That does allow me to define the path of the mxd to a folder, but what about the overwrite capability?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
arcpy.env.overwriteOutput = True&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My env.workspace is currently defined to the gdb, so it still won't allow me to overwrite the mxd.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:06:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340318#M26709</guid>
      <dc:creator>Michele</dc:creator>
      <dc:date>2021-12-11T16:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: error with mxd.save/mxd.SaveACopy</title>
      <link>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340319#M26710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is just a simple thought, but...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 May 2015 20:42:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-with-mxd-save-mxd-saveacopy/m-p/340319#M26710</guid>
      <dc:creator>JulianaQuist</dc:creator>
      <dc:date>2015-05-27T20:42:32Z</dc:date>
    </item>
  </channel>
</rss>

