<?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: Unable to save the MXD using external python script. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/unable-to-save-the-mxd-using-external-python/m-p/180192#M13835</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Randu Burton, Thanks for you're reply. I tried you're suggestion but its not working giving me the same error as "AssertionError: Invalid MXD filename.".&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just for you're information there is no file with name "testfile.mxd" all I am trying to save the view as MXD which is not working.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 03 Jul 2019 16:38:20 GMT</pubDate>
    <dc:creator>krishmandali</dc:creator>
    <dc:date>2019-07-03T16:38:20Z</dc:date>
    <item>
      <title>Unable to save the MXD using external python script.</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-save-the-mxd-using-external-python/m-p/180190#M13833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;I am writing a small automation to create a view, register the view in Geo database and publish it as a service. So far good with creating a view and register with Geo database but I am trying to save the mxd before publishing it and its not working out. I saving the registered view in following ways and not working&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd = arcpy.mapping.MapDocument(&lt;SPAN style="color: #008000; border: 0px; font-weight: bold; font-size: 12px;"&gt;"C:\GIS&lt;/SPAN&gt;&lt;SPAN style="color: #000080; border: 0px; font-weight: bold; font-size: 12px;"&gt;\t&lt;/SPAN&gt;&lt;SPAN style="color: #008000; border: 0px; font-weight: bold; font-size: 12px;"&gt;estfile.mxd"&lt;/SPAN&gt;) 

&lt;STRONG style="border: 0px; font-weight: bold; font-size: 12px;"&gt;Error&lt;/STRONG&gt;: AssertionError: Invalid MXD filename.

------------------------------------------------------------

&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd = arcpy.mapping.MapDocument(&lt;SPAN style="color: #008000; border: 0px; font-weight: bold; font-size: 12px;"&gt;"CURRENT"&lt;/SPAN&gt;)


&lt;STRONG style="border: 0px; font-weight: bold; font-size: 12px;"&gt;Error&lt;/STRONG&gt; : RuntimeError: Object: CreateObject cannot open map documen&lt;/PRE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:12:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-save-the-mxd-using-external-python/m-p/180190#M13833</guid>
      <dc:creator>krishmandali</dc:creator>
      <dc:date>2021-12-11T09:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save the MXD using external python script.</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-save-the-mxd-using-external-python/m-p/180191#M13834</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you try:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;mxd &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mapping&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MapDocument&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;"C:\GIS\testfile.mxd"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The r before the quoted text of the file name will cause Python to interpret the string as raw text.&amp;nbsp; Otherwise, it would see the \t as an escaped&amp;nbsp;tab character.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jul 2019 16:30:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-save-the-mxd-using-external-python/m-p/180191#M13834</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2019-07-03T16:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save the MXD using external python script.</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-save-the-mxd-using-external-python/m-p/180192#M13835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Randu Burton, Thanks for you're reply. I tried you're suggestion but its not working giving me the same error as "AssertionError: Invalid MXD filename.".&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just for you're information there is no file with name "testfile.mxd" all I am trying to save the view as MXD which is not working.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jul 2019 16:38:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-save-the-mxd-using-external-python/m-p/180192#M13835</guid>
      <dc:creator>krishmandali</dc:creator>
      <dc:date>2019-07-03T16:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save the MXD using external python script.</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-save-the-mxd-using-external-python/m-p/180193#M13836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Then perhaps:&lt;/P&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;mxd.saveACopy(r"C:\GIS\testfile.mxd")‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;See &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/mapdocument-class.htm"&gt;MapDocument&lt;/A&gt;&amp;nbsp;for more info as you can specify the version format.&amp;nbsp; There is also save().&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jul 2019 16:46:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-save-the-mxd-using-external-python/m-p/180193#M13836</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2019-07-03T16:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save the MXD using external python script.</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-save-the-mxd-using-external-python/m-p/180194#M13837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not even getting to that point. Creating MXD object itself is getting error.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jul 2019 17:06:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-save-the-mxd-using-external-python/m-p/180194#M13837</guid>
      <dc:creator>krishmandali</dc:creator>
      <dc:date>2019-07-03T17:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save the MXD using external python script.</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-save-the-mxd-using-external-python/m-p/180195#M13838</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Perhaps if you could share a bit more of what you are doing would be helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's a bit of an example of working with an mxd document (in this case to make adjustments to the visibility and transparency of some map layers):&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy

mxd &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mapping&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MapDocument&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;"C:\Project\Project.mxd"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# or if inside ArcMap:&lt;/SPAN&gt;
mxd &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mapping&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MapDocument&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"CURRENT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

df &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mapping&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListDataFrames&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;mxd&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"County Maps"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# ListLayers (map_document_or_layer, {wildcard}, {data_frame})&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; lyr &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mapping&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;mxd&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Lakes"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; df&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;description &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"USGS Lakes"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;visible &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;
        lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;transparency &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;50&lt;/SPAN&gt;

mxd&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;save&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# save the document with changes&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# or&lt;/SPAN&gt;
mxd&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;saveACopy&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;"C:\GIS\testfile.mxd"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# save the changes to a new document&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;del&lt;/SPAN&gt; mxd‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In line 3 or 4, you are opening an mxd to work with.&amp;nbsp; This can be a previously saved document, or the current one opened in ArcMap.&amp;nbsp; Then make your changes to the document.&amp;nbsp;&amp;nbsp; And in lines 16 or 18 you are saving the changes to either the original document or a new document.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:12:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-save-the-mxd-using-external-python/m-p/180195#M13838</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2021-12-11T09:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save the MXD using external python script.</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-save-the-mxd-using-external-python/m-p/180196#M13839</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Randy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;import &lt;/SPAN&gt;arcpy

arcpy.env.workspace = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;r"Database Connections\Connection to SVTHCPHDW.sde"
&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;
&lt;/SPAN&gt;arcpy.CreateDatabaseView_management(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Database Connections\Connection to SVTHCPHDW.sde"&lt;/SPAN&gt;,&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Testagain"&lt;/SPAN&gt;,&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"SELECT TOP (1000) [K_And_FW_key]       ,[zip]       ,[Shape]  ,[GeographyBaseline]       ,[Year]       ,[geography_key]       ,[DP05_0033]       ,[DP05_33E_EstNote]       ,[DP05_33E_Est]       ,[DP05_33E_ErrMgn]       ,[DP05_33E_ErrMgnNote]       ,[DP05_33PE_Pct]       ,[DP05_33PE_PctNote]       ,[DP05_33PE_PctErrMgn]       ,[DP05_33PE_PctErrMgnNote]       ,[DP05_0034]       ,[DP05_34E_EstNote]       ,[DP05_34E_Est]       ,[DP05_34E_ErrMgn]       ,[DP05_34E_ErrMgnNote]       ,[DP05_34PE_Pct]       ,[DP05_34PE_PctNote]       ,[DP05_34PE_PctErrMgn]       ,[DP05_34PE_PctErrMgnNote]       ,[DP05_0035]       ,[DP05_35E_EstNote]       ,[DP05_35E_Est]       ,[DP05_35E_ErrMgn]       ,[DP05_35E_ErrMgnNote]       ,[DP05_35PE_Pct]       ,[DP05_35PE_PctNote]       ,[DP05_35PE_PctErrMgn]       ,[DP05_35PE_PctErrMgnNote]   FROM [DWAcs].[rpt].[Pivot_ZipCode_Acs5DP05_GISTest]"&lt;/SPAN&gt;)
&lt;SPAN style="color: #000080; font-weight: bold;"&gt;print &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"view created sucessfully"
&lt;/SPAN&gt;inTable = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;r"Database Connections\Connection to SVTHCPHDW.sde\Testagain"
&lt;/SPAN&gt;oid_field = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"OID"
&lt;/SPAN&gt;inTable = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;r"Database Connections\Connection to SVTHCPHDW.sde\Testagain"
&lt;/SPAN&gt;oid_field = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"K_And_FW_key"
&lt;/SPAN&gt;shape_field = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Shape"
&lt;/SPAN&gt;geometry_type = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"POLYGON"
&lt;/SPAN&gt;sr = arcpy.SpatialReference(&lt;SPAN style="color: #0000ff;"&gt;4326&lt;/SPAN&gt;)
in_extent = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;""
&lt;/SPAN&gt;arcpy.RegisterWithGeodatabase_management(inTable, oid_field, shape_field,
                                         geometry_type, sr, in_extent)

mxd = arcpy.mapping.MapDocument(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"CURRENT"&lt;/SPAN&gt;)//&lt;STRONG&gt;This one is creating error&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;I don't have mxd file previously saved in location. Need to save it after I registered the view with Geo Database.(on fly)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:12:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-save-the-mxd-using-external-python/m-p/180196#M13839</guid>
      <dc:creator>krishmandali</dc:creator>
      <dc:date>2021-12-11T09:12:49Z</dc:date>
    </item>
  </channel>
</rss>

