<?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: arcpy.mapping.MapDocument('CURRENT') error in Debug only in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648211#M50472</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What's "debug mode"? The Python window?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A standalone script running in its own process (say, from PyScripter) isn't using ArcMap's arcpy process so it won't be able to see "CURRENT".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 May 2015 05:10:29 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2015-05-20T05:10:29Z</dc:date>
    <item>
      <title>arcpy.mapping.MapDocument('CURRENT') error in Debug only</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648210#M50471</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When attempting the command from ArcMap in Debug mode:&lt;/P&gt;&lt;P&gt;mxd = arcpy.mapping.MapDocument('CURRENT') &lt;BR /&gt;I now receive the error: "Object: CreateObject cannot open map document"&lt;/P&gt;&lt;P&gt;However, when I "run" the script in ArcMap, the error does NOT occur. Why would this be the case? This makes debugging impossible...&lt;/P&gt;&lt;P&gt;Yes, I have "Always Run in foreground" checked (and even disabled all background processing as a test as well).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;running ArcGis Desptop Advanced 10.2.2 and using PyScripter IDE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Bill D. Richards&lt;/P&gt;&lt;P&gt;North IDaho College&lt;/P&gt;&lt;P&gt;Dept of Geography/Geology&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 May 2015 21:08:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648210#M50471</guid>
      <dc:creator>BillRichards</dc:creator>
      <dc:date>2015-05-19T21:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.MapDocument('CURRENT') error in Debug only</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648211#M50472</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What's "debug mode"? The Python window?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A standalone script running in its own process (say, from PyScripter) isn't using ArcMap's arcpy process so it won't be able to see "CURRENT".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 05:10:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648211#M50472</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2015-05-20T05:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.MapDocument('CURRENT') error in Debug only</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648212#M50473</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The documentation can be found in &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/MapDocument/00s30000000r000000/"&gt;arcpy.mapping discussion&lt;/A&gt; here and&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/MapDocument/00s30000000n000000/"&gt; in here .&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Visually, here is a picture of running the command line within PythonWin and ArcMaps IDLE script editor access.&amp;nbsp; PythonWin gives an error since it does not know what CURRENT is&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="101491" alt="Arcpy_mapping_IDE_access.png" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/101491_Arcpy_mapping_IDE_access.png" style="width: 620px; height: 355px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now give it a name for use outside arcmap&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Arcpy_mapping_IDE_access2.png" class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/101712_Arcpy_mapping_IDE_access2.png" style="width: 620px; height: 287px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 08:18:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648212#M50473</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-05-20T08:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.MapDocument('CURRENT') error in Debug only</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648213#M50474</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;By "debug" mode I mean: In ArcMap (with the map document open), open the Toolbox window, right-click on the script and select "Debug" rather than "Open" or "Edit". In other words, this is NOT a standalone script to be run outside of ArcMap..... I have this script set to run "in process" not in it's own process......&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 15:21:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648213#M50474</guid>
      <dc:creator>BillRichards</dc:creator>
      <dc:date>2015-05-20T15:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.MapDocument('CURRENT') error in Debug only</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648214#M50475</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So, what you are saying is that, even though I am within ArcMap and have activated the "Debug" for the script from with the ArcMap-based toolbox, the debug session is running "outside" of ArcMap. How, then, can ANY debugging occur while in ArcMap if you need to access the current map document unless you hard-code the document each time you debug (and then reset to "CURRENT" for run-time)? &lt;/P&gt;&lt;P&gt;As an update: setting the document argument to the fully qualified filename does allow me to continue my debug session, but causes other issues that I will need to investigate....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 15:30:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648214#M50475</guid>
      <dc:creator>BillRichards</dc:creator>
      <dc:date>2015-05-20T15:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.MapDocument('CURRENT') error in Debug only</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648215#M50476</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have PythonWin set as my debug and it was running when I gave that example in the image.&amp;nbsp; If I was editing a script and then used a tool in arctoolbox which used that script, the script gets reloaded with the changes.&amp;nbsp; It has to be refreshed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On a side note, using the IDE within ArcMap means you don't have to load arcpy when you try code snippets.&amp;nbsp; Try that with your editor IDE...won't work...you have to load it.&amp;nbsp; I like this scenario because I don't have to worry about conflicts.&amp;nbsp; I can run Pyscripter, Pythonwin and the Python IDE in ArcMap and the software doesn't get confused (...although sometimes the user does...)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 17:46:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648215#M50476</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-05-20T17:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.MapDocument('CURRENT') error in Debug only</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648216#M50477</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As noted previously,&lt;/P&gt;&lt;P&gt;once I hard-code the map document with a fully qualified path and name, the call to "arcpy.mapping.MapDocument(filepath)" succeeds and debugging in Pyscripter can continue. However, calls to change the DefinitionQuery, for example, have no effect (even after a call to RefreshActiveView). It's as if the debug session is sending nothing back to ArcMap (or ArcMap is ignoring it). As per your response, I am aware that code snippets should operate fine from with the "Python window", but I want to debug the entire script, not just bits of it. Is this simply not possible in ArcMap (as in ArcCatalog)?&lt;/P&gt;&lt;P&gt;Also, you make mention of "Python IDE", are you referring to IDLE?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 May 2015 16:15:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648216#M50477</guid>
      <dc:creator>BillRichards</dc:creator>
      <dc:date>2015-05-21T16:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.MapDocument('CURRENT') error in Debug only</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648217#M50478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My workflow if I have to have arcmap open...which is rarely....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;create a simple tool in a simple toolbox (I call this JunkTools)&lt;/LI&gt;&lt;LI&gt;I attach any parameters to the tool so that they are associated with my script, for example, you can have your project as one of your parameters, a featurelayer as another etc.&lt;/LI&gt;&lt;LI&gt;this now just allows your script to communicate with a project and its components in ArcMap.&lt;/LI&gt;&lt;LI&gt;If I have a script error, or I want to edit the script to change its functionality, I will edit the script in PythonWin or PyScripter depending on how I am feeling that day&lt;/LI&gt;&lt;LI&gt;I then rerun the script tool from the toolbox&lt;/LI&gt;&lt;LI&gt;In the above scenario, you don't have to really modify your script since your script still needs parameters but running the script from a tool allows the association between the script and ArcMap.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It works for me, when I have to 'do something' and have arcmap open.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another trick I often use (not just with arcmap) is to place the script in the same folder as the 'object' that you want to work with...say an *.mxd.&amp;nbsp; You can then exploit fact that sys.argv[0] is the running script.&amp;nbsp; This you may find useful. It is what I use when I have to work with *.mxd's&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import sys
import os
import numpy as np
script = sys.argv[0]
path,name = os.path.split(script)
mxd = path + '\\test.mxd'
print('\nScript:... {}\nFolder:... {}\nProject:... {} '.format(name,path,mxd))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:29:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648217#M50478</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T03:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.MapDocument('CURRENT') error in Debug only</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648218#M50479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;EM&gt;&amp;gt; &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;It's as if the debug session &lt;STRONG&gt;is sending nothing back to ArcMap&lt;/STRONG&gt; (or ArcMap is ignoring it).&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, that's exactly right. The debug opens a new python.exe process in IDE (Interactive Development Environment, i.e. IDLE, PyScripter, etc).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using arcpy.mapping to alter the current map is a special case, as to alter the current map you need to be in the ArcMap python session. (sys.executable is ArcMap.exe).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The IDE is in its own python.exe shell apart from ArcMap, even running "in-process" it's a sub process, it can't "reach back" to the objects loaded&amp;nbsp; in ArcMap's "CURRENT" document.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The easiest way to test python code that uses arcpy.mapping to alter the ArcMap current session is to load it or paste it into the ArcMap Python window.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 24 May 2015 04:39:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648218#M50479</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2015-05-24T04:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.MapDocument('CURRENT') error in Debug only</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648219#M50480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for EXPLICITLY clearing that up &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;My experience has been significantly concentrated on standalone geoprocessing (as well as high-performance computing - HPC - from the "old" days). I am creating some exercises for students to compare creating/debugging tools for ArcMap with Autocad and the Visual Lisp IDE. In Visual Lisp IDE, the code is always connected to the map document and you can always see (in the Autocad map document) the immediate actions during debugging...&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 24 May 2015 04:55:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-mapdocument-current-error-in-debug/m-p/648219#M50480</guid>
      <dc:creator>BillRichards</dc:creator>
      <dc:date>2015-05-24T04:55:03Z</dc:date>
    </item>
  </channel>
</rss>

