Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Close ArcMap using Python AddIn Extension

$
0
0
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 Code:

def beforeCloseDocument(self):
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 Code:

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':
            #time.sleep(30)
            #os.system("pause")
            os.system('taskkill /IM Arcmap*')#is killing it too soon
            #time.sleep(15)
        pass
           
    def beforeCloseDocument(self):
        #mxd = arcpy.mapping.MapDocument("CURRENT")
        if mxd.description == 'Print to PDF':
            arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")
        pass


Viewing all articles
Browse latest Browse all 2485

Trending Articles