<?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 when running code as toolbox script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727652#M56419</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you very much&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 26 Jun 2013 14:41:08 GMT</pubDate>
    <dc:creator>SithikSabithaAbdulkani</dc:creator>
    <dc:date>2013-06-26T14:41:08Z</dc:date>
    <item>
      <title>Error when running arcpy.mapping code as toolbox script</title>
      <link>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727650#M56417</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The following code works fine when I copy and paste it to the python command window.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
df.name&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It produces the following errors when I run the script in the Python shell (F5) and similar errors if I try to use it as a script from a toolbox.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "C:\gisdata\python\test.py", line 3, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcPy\arcpy\arcobjects\mixins.py", line 441, in __init__&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; super(MapDocumentMethods, self).__init__(mxd)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcPy\arcpy\arcobjects\_base.py", line 47, in __init__&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; for arg in args))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RuntimeError: Object: CreateObject cannot open map document&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there something special I need to add/setup etc, to run in those other modes?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Never mind.&lt;/STRONG&gt;&lt;SPAN&gt; I figured out that I didn't have the "Always run in foreground" check box selected as needed when using "CURRENT".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Scott&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:51:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727650#M56417</guid>
      <dc:creator>ScottOatley</dc:creator>
      <dc:date>2021-12-12T16:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: Error when running code as toolbox script</title>
      <link>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727651#M56418</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Although you identified that script tools using the CURRENT keyword can only be run in the foreground, please note that when creating a MapDocument object you will only want to ONLY use the CURRENT keyword if you're working from within ArcMap via a Script Tool or the Python window.&amp;nbsp; If you attempt to create a MapDocument object outside of ArcMap (i.e. ArcCatalog, a Python IDE, etc.) with the CURRENT keyword you will receive a similar runtime error.&amp;nbsp; When working in an environment outside of ArcMap you will want to reference the file path to the mxd instead of using the CURRENT keyword.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Mar 2012 23:26:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727651#M56418</guid>
      <dc:creator>FreddieGibson</dc:creator>
      <dc:date>2012-03-03T23:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: Error when running code as toolbox script</title>
      <link>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727652#M56419</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you very much&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2013 14:41:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727652#M56419</guid>
      <dc:creator>SithikSabithaAbdulkani</dc:creator>
      <dc:date>2013-06-26T14:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: Error when running code as toolbox script</title>
      <link>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727653#M56420</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for the clarification, concerning CURRENT and REFERENCE FILE PATH! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Aug 2014 12:12:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727653#M56420</guid>
      <dc:creator>RaresRotar</dc:creator>
      <dc:date>2014-08-11T12:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: Error when running code as toolbox script</title>
      <link>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727654#M56421</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I get this error running from ArcMap 10.5 when when I insert my script tool into a ModelBuilder model. &amp;nbsp;Both the original script tool and the ModelBuilder tool are set to run in the foreground. &amp;nbsp;I do not get the error if I use the script tool outside of ModelBuilder.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Mar 2017 20:41:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727654#M56421</guid>
      <dc:creator>SethPaine1</dc:creator>
      <dc:date>2017-03-29T20:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Error when running code as toolbox script</title>
      <link>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727655#M56422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Seth, I would recommend starting a new question post/thread. &amp;nbsp;INclude a few more details, the exact error and if possible, the python code in question following &lt;A href="https://community.esri.com/people/curtvprice/blog/2014/09/25/posting-code-blocks-in-the-new-geonet?sr=search&amp;amp;searchId=4a5ca233-9c1e-4622-8305-c67b1cd9eabf&amp;amp;searchIndex=4"&gt;https://community.esri.com/people/curtvprice/blog/2014/09/25/posting-code-blocks-in-the-new-geonet?sr=search&amp;amp;searchId=4a5ca233-9c1e-4622-8305-c67b1cd9eabf&amp;amp;searchIndex=4&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;also, you can tag other groups with the @ and the group name like @modelbuilder&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Mar 2017 03:10:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727655#M56422</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2017-03-30T03:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: Error when running arcpy.mapping code as toolbox script</title>
      <link>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727656#M56423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@&lt;A _jive_internal="true" data-userid="14792" data-username="FGibson-esristaff" href="https://community.esri.com/people/FGibson-esristaff" style="color: #8ca9cd; background-color: #ffffff; border: 0px; font-weight: 200; text-decoration: none; font-size: 1.286rem;" target="_blank"&gt;Freddie Gibson&lt;/A&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; font-weight: bold;"&gt;"C:\GIS&lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;\t&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;estfile.mxd"&lt;/SPAN&gt;) 

&lt;STRONG&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; font-weight: bold;"&gt;"CURRENT"&lt;/SPAN&gt;)


&lt;STRONG&gt;Error&lt;/STRONG&gt; : RuntimeError: Object: CreateObject cannot open map document&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:07:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727656#M56423</guid>
      <dc:creator>krishmandali</dc:creator>
      <dc:date>2021-12-12T07:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Error when running arcpy.mapping code as toolbox script</title>
      <link>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727657#M56424</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 document&lt;/PRE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:07:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-running-arcpy-mapping-code-as-toolbox/m-p/727657#M56424</guid>
      <dc:creator>krishmandali</dc:creator>
      <dc:date>2021-12-12T07:07:04Z</dc:date>
    </item>
  </channel>
</rss>

