Solved! Go to Solution.
import arcpy import subprocess 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" objNewProcess = subprocess.Popen([strArcMapPath, strMxd]) objNewProcess.wait() # this line will wait for the new process to end print "Script completed successfully."
import arcpy import pythonaddins 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': arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")
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]
badList = ['ArcMap.exe']
Thanks for the info Stacey. 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. You'll see in my posted code, that I'm using an AddIn Extension that runs as soon as the MXD opens. However, the process executes too soon, and tries to kill ArcMap before the MXD fully opens. 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. 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. The whole thing has to be timed just right so that the layout fully assembles, then the PritnToPDF function executes.
import arcpy import os mxd = arcpy.mapping.MapDocument("CURRENT") if mxd.description == 'Print to PDF': arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT") os.system('taskkill /IM Arcmap*')
import arcpy import os mxd = arcpy.mapping.MapDocument("CURRENT") if mxd.description == 'Print to PDF': arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT") arcpy.mapping.ListLayers(mxd) os.system('taskkill /IM Arcmap*')