OK, well I managed to get the code to execute after the MXD opens using an AddIn Extension. However, the code runs before the MXD can fully assemble the layout. It's running the PrintToPDF function so I need the layout to be complete before it runs so that the PDF generates correctly. I've tried using time.sleep to stall it while the file opens, but that doesn't seem to work. It seems to just stall the actual opening of the file.
Anyone have any ideas on how to get the arcpy.mapping.PrintMap function to run after the MXD fully opens, and assembles the map layout? Here's the code I'm trying:
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):
time.sleep(10)
mxd = arcpy.mapping.MapDocument("CURRENT")
if mxd.description == 'Print to PDF':
arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")
pass