<?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 How to check if an mxd is open? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-check-if-an-mxd-is-open/m-p/754776#M58201</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a script that adds layer files to a map and optionally saves it. If the map is open, I just reference the map like normal, i.e. mxd = arcpy.mapping.MapDocument("CURRENT").&lt;/P&gt;&lt;P&gt;I'd like to be able to check whether the map is open in the first place, so I can reference the map through a parameter if it isn't.&lt;/P&gt;&lt;P&gt;What I've come up with so far is to use a try/except block to catch the runtime error generated if the mxd is not open, then set it to a default if so.&lt;/P&gt;&lt;P&gt;Is there a way to check if the map is open or not? Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Dec 2017 12:31:04 GMT</pubDate>
    <dc:creator>Zeke</dc:creator>
    <dc:date>2017-12-07T12:31:04Z</dc:date>
    <item>
      <title>How to check if an mxd is open?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-check-if-an-mxd-is-open/m-p/754776#M58201</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a script that adds layer files to a map and optionally saves it. If the map is open, I just reference the map like normal, i.e. mxd = arcpy.mapping.MapDocument("CURRENT").&lt;/P&gt;&lt;P&gt;I'd like to be able to check whether the map is open in the first place, so I can reference the map through a parameter if it isn't.&lt;/P&gt;&lt;P&gt;What I've come up with so far is to use a try/except block to catch the runtime error generated if the mxd is not open, then set it to a default if so.&lt;/P&gt;&lt;P&gt;Is there a way to check if the map is open or not? Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Dec 2017 12:31:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-check-if-an-mxd-is-open/m-p/754776#M58201</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2017-12-07T12:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an mxd is open?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-check-if-an-mxd-is-open/m-p/754777#M58202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try/except is fine, this is what happens when you do the equivalent in Pro, so I imagine that arcmap behaves the same.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;try&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; aprx &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ArcGISProject&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;
&lt;SPAN class="keyword token"&gt;except&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"big failure"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
big failure‍‍‍‍‍‍&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;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:01:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-check-if-an-mxd-is-open/m-p/754777#M58202</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T08:01:03Z</dc:date>
    </item>
  </channel>
</rss>

