AnsweredAssumed Answered

Close ArcMap using Python AddIn Extension

Question asked by NPPD_IP on Sep 9, 2013
Latest reply on Sep 16, 2013 by stacyrendall
I've written a couple of Python scripts that open ArcMap, run a Python AddIn Extension, then hopefully close ArcMap.  As an MXD document is opened, the AddIn extension runs the [HTML]def beforeCloseDocument(self):[/HTML] function.  However I can't seem to figure out how to close ArcMap after the MXD has completely opened.  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.  Here's the code from my AddIn Extension.  Any advice would be much apprciated.  I'm hitting a wall here, and just can't seem to get anywhere with this.

[HTML]import arcpy
import pythonaddins
import os
import time

class ExtensionClass1(object):
    """Implementation for PrintToPDF_AddIn_addin.extension2 (Extension)"""
    def __init__(self):
        # For performance considerations, please remove all unused methods in this class.
        self.enabled = True

    def openDocument(self):
        mxd = arcpy.mapping.MapDocument("CURRENT")
        if mxd.description == 'Print to PDF':
            os.system('taskkill /IM Arcmap*')#is killing it too soon
    def beforeCloseDocument(self):
        #mxd = arcpy.mapping.MapDocument("CURRENT")
        if mxd.description == 'Print to PDF':
            arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")