<?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: Close ArcMap using Python AddIn Extension in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230116#M17836</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OK, here's what I finally figured out.&amp;nbsp; It all comes down to the "Zoom To Percentage" in the map layout.&amp;nbsp; All along I???ve noticed that printing to a PDF file seemed to build the layout tables correctly, but the table would be too small.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In ArcMap:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]27486[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The resulting Output PDF:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]27487[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However when I changed the "Zoom to Percentage" in the layout, the results looked like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In ArcMap:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]27488[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The resulting Output PDF:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]27489[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Go figure as to why, but it works!&amp;nbsp; For me my magic number was 245%.&amp;nbsp; I think it'll vary for each user depending on how they have their toolbars setup, etc.&amp;nbsp; This value also applied to both 8.5x11 and 11x17 landscape layouts.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So as a recap I used this script to launch ArcMap and open the MXD file:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import subprocess&amp;nbsp; strArcMapPath = r"C:\Program Files (x86)\ArcGIS\Desktop10.1\bin\ArcMap.exe" strMxd = r"D:\Users\Products\PSA Map Updates\Automation\PSA Location Map - Final.mxd"&amp;nbsp; objNewProcess = subprocess.Popen([strArcMapPath, strMxd]) objNewProcess.wait() # this line will wait for the new process to end&amp;nbsp; print "Script completed successfully."&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then this one as my Python AddIn script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import pythonaddins&amp;nbsp; class ExtensionClass1(object): &amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for PrintToPDF_AddIn_addin.extension2 (Extension)""" &amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # For performance considerations, please remove all unused methods in this class. &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; def openDocument(self): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mxd.description == 'Print to PDF': &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now I was orignally trying to close ArcMap in order to execute the PrintMap function before close, however this method works at open.&amp;nbsp; I still can't believe it.&amp;nbsp; Keep in mind that this process requires a PDF print driver of some sort in order to work.&amp;nbsp; I have Adobe Acrobat installed which includes an "Adobe PDF" driver, however there are a few freebies out there that shouldwork just as well (i.e. CutePDF, etc...)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I plan to forward this to out customer support rep to see if that will help move things along with the bug fix.&amp;nbsp; Thanks for all the input, and assistance.&amp;nbsp; If anyone has any questions feel free to contact me.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 16 Sep 2013 16:55:39 GMT</pubDate>
    <dc:creator>EricMahaffey</dc:creator>
    <dc:date>2013-09-16T16:55:39Z</dc:date>
    <item>
      <title>Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230102#M17822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've written a couple of Python scripts that open ArcMap, run a Python AddIn Extension, then hopefully close ArcMap.&amp;nbsp; As an MXD document is opened, the AddIn extension runs the [HTML]def beforeCloseDocument(self):[/HTML] function.&amp;nbsp; However I can't seem to figure out how to close ArcMap after the MXD has completely opened.&amp;nbsp; Basically I'm trying to work around a known bug in which the ExportToPDF and PrintMap functions will not work correctly with layouts that have attribute tables embeded in them.&amp;nbsp; Here's the code from my AddIn Extension.&amp;nbsp; Any advice would be much apprciated.&amp;nbsp; I'm hitting a wall here, and just can't seem to get anywhere with this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[HTML]import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import pythonaddins&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import time&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;class ExtensionClass1(object):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for PrintToPDF_AddIn_addin.extension2 (Extension)"""&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # For performance considerations, please remove all unused methods in this class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def openDocument(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mxd.description == 'Print to PDF':&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #time.sleep(30)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #os.system("pause")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.system('taskkill /IM Arcmap*')#is killing it too soon&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #time.sleep(15)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def beforeCloseDocument(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mxd.description == 'Print to PDF':&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass[/HTML]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Sep 2013 10:58:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230102#M17822</guid>
      <dc:creator>EricMahaffey</dc:creator>
      <dc:date>2013-09-09T10:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230103#M17823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Something like this should work, using the &lt;/SPAN&gt;&lt;A href="https://code.google.com/p/psutil/" rel="nofollow noopener noreferrer" target="_blank"&gt;Psutil library&lt;/A&gt;&lt;SPAN&gt; for Python:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import psutil
# list of process names that we might want to terminate
badList = ['ArcMap.exe', 'AppROT.exe', 'ArcGISConnection.exe', 'ArcGISCacheMgr.exe']

# generate list of processes to terminate
badProcesses = [p for p in psutil.process_iter() if p.name in badList]

# terminate the bad processes
[p.terminate() for p in badProcesses]
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is a bit zealous about terminating all the Arc processes, you can probably get away with changing badList to just:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;badList = ['ArcMap.exe']&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:11:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230103#M17823</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-11T11:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230104#M17824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the info Stacey.&amp;nbsp; I'm able to get the ArcMap process to teminate using [HTML]os.system('taskkill /IM Arcmap*'[/HTML], but I can't seem to get it to run after a delay.&amp;nbsp; You'll see in my posted code, that I'm using an AddIn Extension that runs as soon as the MXD opens.&amp;nbsp; However, the process executes too soon, and tries to kill ArcMap before the MXD fully opens.&amp;nbsp; When I add time.sleep() or similar it just delays the openeing of the document, not the next part of the script which is the arcpy.mapping.PrintMap function.&amp;nbsp; Because of the limitations with AddIn functions, PrintToPDF has to run before the document closes in order to capture all the tables after they've fully loaded.&amp;nbsp; The whole thing has to be timed just right so that the layout fully assembles, then the PritnToPDF function executes.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 09:47:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230104#M17824</guid>
      <dc:creator>EricMahaffey</dc:creator>
      <dc:date>2013-09-10T09:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230105#M17825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I seems clear that you are using the os module to kill the Arc process, so the document never gets to close.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Instead it is stabbed in the back by the os.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe you need to put everything inthe openDocument function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pause there to alow the tables to load before runing printToPDF&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and only then kill the process off (after the printing has finished).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 13:31:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230105#M17825</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2013-09-10T13:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230106#M17826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Mark, thanks for the suggestions.&amp;nbsp; I've tried running the "arcpy.mapping.PrintMap" function in the "def openDocument(self): " function.&amp;nbsp; However, I can't get the process to stall long enough for the layout to fully assemble the tables before the PrintMap executes.&amp;nbsp; What I get are tiny tables, or incomplete ones.&amp;nbsp; I tried to use time.sleep() to pause the script while the MXD is opening, but all that does is pause the open process and not the script.&amp;nbsp; Any ideas how I can properly pause the script while the MXD is opening and assembling?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 13:46:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230106#M17826</guid>
      <dc:creator>EricMahaffey</dc:creator>
      <dc:date>2013-09-10T13:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230107#M17827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks for the info Stacey.&amp;nbsp; I'm able to get the ArcMap process to teminate using [HTML]os.system('taskkill /IM Arcmap*'[/HTML], but I can't seem to get it to run after a delay.&amp;nbsp; You'll see in my posted code, that I'm using an AddIn Extension that runs as soon as the MXD opens.&amp;nbsp; However, the process executes too soon, and tries to kill ArcMap before the MXD fully opens.&amp;nbsp; When I add time.sleep() or similar it just delays the openeing of the document, not the next part of the script which is the arcpy.mapping.PrintMap function.&amp;nbsp; Because of the limitations with AddIn functions, PrintToPDF has to run before the document closes in order to capture all the tables after they've fully loaded.&amp;nbsp; The whole thing has to be timed just right so that the layout fully assembles, then the PritnToPDF function executes.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Oh, I failed to read your question properly (...at all...?). Sorry!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also noticed that the very bottom line of code from the initial post contains a &lt;/SPAN&gt;&lt;STRONG&gt;pass &lt;/STRONG&gt;&lt;SPAN&gt;statement. This should not be there.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To find the solution for a problem like this you need to strip everything back to the simplest possible set of operations that works, &lt;/SPAN&gt;&lt;STRONG&gt;then &lt;/STRONG&gt;&lt;SPAN&gt;add in the complexity. I would suggest that you initially work in a script; if/once you get a series of steps that does work, you can put it back into the class form. Here is a script that, I think, is doing what you want. It probably won't work either, but it is a lot more clear &lt;/SPAN&gt;&lt;STRONG&gt;what &lt;/STRONG&gt;&lt;SPAN&gt;is happening and &lt;/SPAN&gt;&lt;STRONG&gt;when&lt;/STRONG&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import os

mxd = arcpy.mapping.MapDocument("CURRENT")
if mxd.description == 'Print to PDF':
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")
&amp;nbsp;&amp;nbsp;&amp;nbsp; os.system('taskkill /IM Arcmap*')&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, to get ArcMap to finish before closing you could try to get the code to perform some trivial operation the MXD after it is printed, but before it tries to close. This might be enough to force it to complete the print before the trivial operation is allowed to start, i.e. List Layers:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import os

mxd = arcpy.mapping.MapDocument("CURRENT")
if mxd.description == 'Print to PDF':
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ListLayers(mxd)
&amp;nbsp;&amp;nbsp;&amp;nbsp; os.system('taskkill /IM Arcmap*')&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:11:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230107#M17827</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-11T11:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230108#M17828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Stacy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think you're on to something.&amp;nbsp; When I test each of the pieces in the Python command window within ArcMap they do as expected.&amp;nbsp; However, linking everything together based on timing is the difficult part.&amp;nbsp; So up until now I've been going with the idea of using a Python AddIn Extension so that my code executes within the MXD after a certain event (i.e openDocument, beforeCloseDocument, closeDocument, and even itemAdded).&amp;nbsp; No matter what I try I can't seem to get my main function "arcpy.mapping.PrintMap" to execute at the right time.&amp;nbsp; I took some of your advice and tried this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[HTML]import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import pythonaddins&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import time&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;class ExtensionClass1(object):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for PrintToPDF_AddIn_addin.extension2 (Extension)"""&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # For performance considerations, please remove all unused methods in this class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def openDocument(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mxd.description == 'Print to PDF':&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layers = arcpy.mapping.ListLayers(mxd, "", "Layers"):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print layers&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; time.sleep(1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.system('taskkill /IM Arcmap*')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def beforeCloseDocument(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")[/HTML]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So while opening the MXD it's listing the layers, but the file isn't continuing to open as this process occurs.&amp;nbsp; ArcMap waits until all the layers have been listed before it completely assembles the layout.&amp;nbsp; When I added the os.system('taskkill /IM Arcmap*') it would list all the layers then crush ArcMap before it could execute the arcpy.mapping.PrintMap.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It's all about timing, and I can't seem to control when things happen. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Sep 2013 17:27:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230108#M17828</guid>
      <dc:creator>EricMahaffey</dc:creator>
      <dc:date>2013-09-11T17:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230109#M17829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Eric,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;as I said before: my advice is to leave the Python AddIn Extension until you get something that works from a script. A script is not the same as the command window: the time it takes for you to enter the commands (or copy/paste them) might be enough for Arc to finish the preceding operations.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The reason I am asking you to do this is that I have no idea &lt;/SPAN&gt;&lt;STRONG style="font-style: italic;"&gt;how&lt;/STRONG&gt;&lt;SPAN&gt; the Python AddIn Extension works, what its execution order is, if it tries to use multiple threads, etc. Once you have something that works from a script it will be simple to implement it within the Python AddIn Extension.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To save and run the script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;OL&gt;&lt;BR /&gt;&lt;LI&gt;copy the first block of code from my previous post (the one without ListLayers) into notepad/IDLE&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;save it somewhere as &lt;SPAN style="font-style:italic;"&gt;test1.py&lt;/SPAN&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;open a command prompt in the folder where &lt;SPAN style="font-style:italic;"&gt;test1.py&lt;/SPAN&gt; is residing&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;locate your ArcGIS Python install (10.0 usually places it at &lt;SPAN style="font-style:italic;"&gt;C:\Python26\ArcGIS10.0\&lt;/SPAN&gt;, 10.1 usually places it at &lt;SPAN style="font-style:italic;"&gt;C:\Python27\ArcGIS10.1\&lt;/SPAN&gt;)&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;test it by entering the full path to &lt;SPAN style="font-style:italic;"&gt;python.exe&lt;/SPAN&gt; at the command line, i.e.: &lt;SPAN style="font-family:Courier New;"&gt;C:\Python27\ArcGIS10.1\python.exe&lt;/SPAN&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;this should open the interpreter, and you can test it is the correct install by running &lt;SPAN style="font-family:Courier New;"&gt;import arcpy&lt;/SPAN&gt;; if everything is OK it will report nothing, just return you to the python command prompt &lt;SPAN style="font-family:Courier New;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;once you have both the above steps working use&lt;SPAN style="font-family:Courier New;"&gt; exit()&lt;/SPAN&gt; to leave the interpreter and run the script like so: &lt;SPAN style="font-family:Courier New;"&gt;C:\Python27\ArcGIS10.1\python.exe test1.py&lt;/SPAN&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;SPAN&gt;What is the output?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now save the second block of code from my previous post as test2.py and repeat the relevant steps of the above process. What is the output now?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Sep 2013 21:16:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230109#M17829</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2013-09-11T21:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230110#M17830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Stacy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again.&amp;nbsp; At this point in my development I'm way past testing each stage of what I'm trying to do (although I did do as you asked and tested each piece but had no luck).&amp;nbsp; That's why I'm in the situation that I'm currently in.&amp;nbsp; Maybe it'll help if I explain why I'm having to do all of these steps in just the right method and order.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For a few years now, ESRI has not responded to a bug that's been reported multiple times (NIM062177 and NIM063441 - "ExportToPDF using arcpy does not export a layer attribute table embedded in a layout").&amp;nbsp; They claim that the bug was rejected because it is "beyond the design of the software".&amp;nbsp; However, the ExportToPDF function works fine with layouts without tables.&amp;nbsp; So it appears that it was never fully tested.&amp;nbsp; So, as a result I am trying to work around the bug, and get my layouts with embeded attribute tables to produce PDF files.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I do know is that if I open my MXD manually in ArcMap and Export to a PDF it drops the wireframe around the tables (but produces the data.&amp;nbsp; If I do this through code only, I get no data).&amp;nbsp; However, if I use the Adobe PDF print driver and print to a file, it works.&amp;nbsp; So, from this I know that I have to do the following things in this exact order and timing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Open the MXD in ArcMap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Wait for the Layout to fully assemble&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Print to file using the Adobe PDF print driver&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. Close ArcMap (hopefully)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The reason I opted to use a Python AddIn Extension is it can be executed within the ArcMap application, and not through code only (which doesn't work).&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So as it stands I have 2 Python scripts.&amp;nbsp; One that launches ArcMap, and opens an MXD, and another which runs in the AddIn Extension:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Open the MXD in ArcMap:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[HTML]import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import subprocess&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;strArcMapPath = r"C:\Program Files (x86)\ArcGIS\Desktop10.1\bin\ArcMap.exe"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;strMxd = r"D:\Users\Products\PSA Map Updates\Automation\PSA Location Map - Final.mxd"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;objNewProcess = subprocess.Popen([strArcMapPath, strMxd])&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;objNewProcess.wait() # this line will wait for the new process to end&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print "Script completed successfully."[/HTML]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Execute Python AddIn Extension:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[HTML]import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import pythonaddins&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import time&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;class ExtensionClass1(object):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for PrintToPDF_AddIn_addin.extension2 (Extension)"""&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # For performance considerations, please remove all unused methods in this class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def openDocument(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mxd.description == 'Print to PDF':&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layers = arcpy.mapping.ListLayers(mxd, "", "Layers"):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print layers&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; time.sleep(1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.system('taskkill /IM Arcmap*')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def beforeCloseDocument(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")[/HTML]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As ArcMap opens, the AddIn Extension executes another Python script (shown above) which queries the MXD properties for a piece of text "Print to PDF" to determine if the map should be Printed To a PDF.&amp;nbsp; If the Description Property does not meet the query it just opens as usual, if it does, I'd &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;like&lt;/SPAN&gt;&lt;SPAN&gt; for it to roll into the PrintMap function which produces the PDF file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The kicker here is that I'm limited to the functions available within the extension class (at least according to the documentation).&amp;nbsp; These functions appear to be run only if a certain event occurs (i.e openDocument, beforeCloseDocument, closeDocument, etc.).&amp;nbsp; That being said I'm trying to figure out a way to execute the "arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")" function inside the extension class as the result of an occurence.&amp;nbsp; When I do this after openDocument, it runs too quickly and the tables do not get added to the PDF correctly.&amp;nbsp; When I try to stall the PrintMap function at openDocument (using ListLayers, time.sleep(), etc.) the actual opening of the file gets stalled.&amp;nbsp; So I opted to try to generate the PDF beforeCloseDocument which is ultimately why I started this thread.&amp;nbsp; I have to programatically close the MXD in order for the PrintMap function to execute.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe there's a way to build a custom extension class function that'll do all this, however, my knowledge of Python is limited to what I've been able to do so far.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hopefully this will help you (or anyone out there) understand what I trying to accomplish.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 12:33:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230110#M17830</guid>
      <dc:creator>EricMahaffey</dc:creator>
      <dc:date>2013-09-12T12:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230111#M17831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Stacy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again.&amp;nbsp; I ran through the tests that you recommended and unfortunately didn't have any luck.&amp;nbsp; At this point I've tested all the steps that need to be run in ArcMap's command window, Python Idle, and Python Command line.&amp;nbsp;&amp;nbsp; That's why I'm in the situation that I'm currently in.&amp;nbsp; Maybe it'll help if I explain why I'm having to do all of these steps using just the right method and order.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For a few years now, ESRI has not responded to a bug that's been reported multiple times (NIM062177 and NIM063441 - "ExportToPDF using arcpy does not export a layer attribute table embedded in a layout").&amp;nbsp; They claim that the bug was rejected because it is "beyond the design of the software".&amp;nbsp; However, the ExportToPDF function works fine with layouts without tables.&amp;nbsp; So it appears that it was never fully tested.&amp;nbsp; So, as a result I am trying to work around the bug, and get my layouts with embeded attribute tables to produce PDF files.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I do know is that if I open my MXD manually in ArcMap and Export to a PDF it drops the wireframe around the tables (but produces the data.&amp;nbsp; If I do this through code only, I get no data).&amp;nbsp; However, if I use the Adobe PDF print driver and print to a file, it works.&amp;nbsp; So, from this I know that I have to do the following things in this exact order and timing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Open the MXD in ArcMap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Wait for the Layout to fully assemble&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Print to file using the Adobe PDF print driver&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. Close ArcMap (hopefully)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The reason I opted to use a Python AddIn Extension is it can be executed within the ArcMap application, and not through code only (which doesn't work).&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So as it stands I have 2 Python scripts.&amp;nbsp; One that launches ArcMap, and opens an MXD, and another which runs in the AddIn Extension:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Open the MXD in ArcMap:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[HTML]import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import subprocess&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;strArcMapPath = r"C:\Program Files (x86)\ArcGIS\Desktop10.1\bin\ArcMap.exe"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;strMxd = r"D:\Users\Products\PSA Map Updates\Automation\PSA Location Map - Final.mxd"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;objNewProcess = subprocess.Popen([strArcMapPath, strMxd])&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;objNewProcess.wait() # this line will wait for the new process to end&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print "Script completed successfully."[/HTML]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Execute Python AddIn Extension:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[HTML]import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import pythonaddins&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import time&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;class ExtensionClass1(object):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for PrintToPDF_AddIn_addin.extension2 (Extension)"""&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # For performance considerations, please remove all unused methods in this class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def openDocument(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mxd.description == 'Print to PDF':&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layers = arcpy.mapping.ListLayers(mxd, "", "Layers"):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print layers&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; time.sleep(1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.system('taskkill /IM Arcmap*')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def beforeCloseDocument(self):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")[/HTML]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As ArcMap opens, the AddIn Extension executes another Python script (shown above) which queries the MXD properties for a piece of text "Print to PDF" to determine if the map should be Printed To a PDF.&amp;nbsp; If the Description Property does not meet the query it just opens as usual, if it does, I'd &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;like&lt;/SPAN&gt;&lt;SPAN&gt; for it to roll into the PrintMap function which produces the PDF file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The kicker here is that I'm limited to the functions available within the extension class (at least according to the documentation).&amp;nbsp; These functions appear to be run only if a certain event occurs (i.e openDocument, beforeCloseDocument, closeDocument, etc.).&amp;nbsp; That being said I'm trying to figure out a way to execute the "arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")" function inside the extension class as the result of an occurence.&amp;nbsp; When I do this after openDocument, it runs too quickly and the tables do not get added to the PDF correctly.&amp;nbsp; When I try to stall the PrintMap function at openDocument (using ListLayers, time.sleep(), etc.) the actual opening of the file gets stalled.&amp;nbsp; So I opted to try to generate the PDF beforeCloseDocument which is ultimately why I started this thread.&amp;nbsp; I have to programatically close the MXD in order for the PrintMap function to execute.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe there's a way to build a custom extension class function that'll do all this, however, my knowledge of Python is limited to what I've been able to do so far.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hopefully this will help you (or anyone out there) understand what I trying to accomplish.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 12:36:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230111#M17831</guid>
      <dc:creator>EricMahaffey</dc:creator>
      <dc:date>2013-09-12T12:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230112#M17832</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Eric,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was trying to spend a bit of time looking into this, but I cannot get Add-In Extensions working on my computer (Buttons and Menus work OK, but Extensions are never added to the Extensions dialog box for me to activate them)...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway, I have a suspicion that the &lt;/SPAN&gt;&lt;STRONG&gt;only&lt;/STRONG&gt;&lt;SPAN&gt; method being run is the &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;openDocument &lt;/SPAN&gt;&lt;SPAN&gt;method, as forcing Arc to close is not necessarily the same thing as closing the MXD...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I was going to test on my computer is the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import pythonaddins

class testExtension(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for arcAddin_addin.testExtension (Extension)"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # For performance considerations, please remove all unused methods in this class.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt = open('D:\\_TEMP\\testOutput.txt', 'w')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.write('File created')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.flush()
&amp;nbsp;&amp;nbsp;&amp;nbsp; def openDocument(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.write('!! openDocument method...')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.flush()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mxd.description == 'Print to PDF':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.write('\t\tDocument contains "Print to PDF" description')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.flush()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layers = arcpy.mapping.ListLayers(mxd, "", "Layers"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.write('\t\t%s' % str(layers))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.flush()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.write('\t\tAbout to kill ArcMap')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.flush()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.system('taskkill /IM Arcmap*')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.write('\t\tThis probably will not appear in the file...')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.flush()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.write('\t\tDocument DOES NOT contain "Print to PDF" description')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.flush()
&amp;nbsp;&amp;nbsp;&amp;nbsp; def beforeCloseDocument(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.write('!! beforeCloseDocument method')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.flush()
&amp;nbsp;&amp;nbsp;&amp;nbsp; def closeDocument(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.write('!! closeDocument method')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.testTxt.flush()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It writes to a text file as each method occurs, so you can see what the add-in extension is doing. flush() is used to force the writes to the file, as we won't be closing it properly. Are you able to temporarily replace your add-in extension python file with the above (after changing the path of the text file to something more appropriate), run it as you normally would and post the contents of the text file?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:11:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230112#M17832</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-11T11:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230113#M17833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Stacy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've had some success.&amp;nbsp; I'm running late getting out of the office today, but I plan to write it all up on Monday.&amp;nbsp; Your never going to believe how I got it to work.&amp;nbsp; Sorry to leave you hanging in suspense over the weekend.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Eric&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Sep 2013 18:42:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230113#M17833</guid>
      <dc:creator>EricMahaffey</dc:creator>
      <dc:date>2013-09-13T18:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230114#M17834</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;As an aside, do you have an Esri account manager assigned to your company? Might be worth pounding on them some if support hasn't been helpful. This seems like a big enough deal for your company that it is absolutely reasonable to escalate it, especially if you're paying yearly maintenance.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Sep 2013 20:27:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230114#M17834</guid>
      <dc:creator>MattSayler</dc:creator>
      <dc:date>2013-09-13T20:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230115#M17835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Stacy,&lt;BR /&gt;&lt;BR /&gt;I've had some success.&amp;nbsp; I'm running late getting out of the office today, but I plan to write it all up on Monday.&amp;nbsp; Your never going to believe how I got it to work.&amp;nbsp; Sorry to leave you hanging in suspense over the weekend.&lt;BR /&gt;&lt;BR /&gt;Eric&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Great, look forward to hearing what works!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Stacy&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 15 Sep 2013 20:52:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230115#M17835</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2013-09-15T20:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230116#M17836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OK, here's what I finally figured out.&amp;nbsp; It all comes down to the "Zoom To Percentage" in the map layout.&amp;nbsp; All along I???ve noticed that printing to a PDF file seemed to build the layout tables correctly, but the table would be too small.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In ArcMap:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]27486[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The resulting Output PDF:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]27487[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However when I changed the "Zoom to Percentage" in the layout, the results looked like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In ArcMap:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]27488[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The resulting Output PDF:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]27489[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Go figure as to why, but it works!&amp;nbsp; For me my magic number was 245%.&amp;nbsp; I think it'll vary for each user depending on how they have their toolbars setup, etc.&amp;nbsp; This value also applied to both 8.5x11 and 11x17 landscape layouts.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So as a recap I used this script to launch ArcMap and open the MXD file:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import subprocess&amp;nbsp; strArcMapPath = r"C:\Program Files (x86)\ArcGIS\Desktop10.1\bin\ArcMap.exe" strMxd = r"D:\Users\Products\PSA Map Updates\Automation\PSA Location Map - Final.mxd"&amp;nbsp; objNewProcess = subprocess.Popen([strArcMapPath, strMxd]) objNewProcess.wait() # this line will wait for the new process to end&amp;nbsp; print "Script completed successfully."&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then this one as my Python AddIn script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import pythonaddins&amp;nbsp; class ExtensionClass1(object): &amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for PrintToPDF_AddIn_addin.extension2 (Extension)""" &amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # For performance considerations, please remove all unused methods in this class. &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; def openDocument(self): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mxd.description == 'Print to PDF': &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now I was orignally trying to close ArcMap in order to execute the PrintMap function before close, however this method works at open.&amp;nbsp; I still can't believe it.&amp;nbsp; Keep in mind that this process requires a PDF print driver of some sort in order to work.&amp;nbsp; I have Adobe Acrobat installed which includes an "Adobe PDF" driver, however there are a few freebies out there that shouldwork just as well (i.e. CutePDF, etc...)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I plan to forward this to out customer support rep to see if that will help move things along with the bug fix.&amp;nbsp; Thanks for all the input, and assistance.&amp;nbsp; If anyone has any questions feel free to contact me.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Sep 2013 16:55:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230116#M17836</guid>
      <dc:creator>EricMahaffey</dc:creator>
      <dc:date>2013-09-16T16:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: Close ArcMap using Python AddIn Extension</title>
      <link>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230117#M17837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Great! Glad you were able to work it out!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Sep 2013 20:25:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-arcmap-using-python-addin-extension/m-p/230117#M17837</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2013-09-16T20:25:22Z</dc:date>
    </item>
  </channel>
</rss>

