import arcpy import pythonaddins class CreateMPKExt(object): """Implementation for CreateMapPackage_addin.mpkext (Extension)""" def __init__(self): # For performance considerations, please remove all unused methods in this class. self.enabled = True def activeViewChanged(self): try: if arcpy.mapping.MapDocument('Current').activeView == 'PAGE_LAYOUT': mpktool.enabled = False else: mpktool.enabled = True except NameError: pass class CreateMPKTool(object): """Implementation for CreateMapPackage_addin.mpktool (Tool)""" def __init__(self): self.enabled = True self.shape = "Rectangle" # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks. self.cursor = 3 def onRectangle(self, rectangle_geometry): import os, win32com.client #Get reference to current map document and set paths to Document and output package mxd = arcpy.mapping.MapDocument('Current') mxdPath = mxd.filePath print "MXD Path: {0}".format(mxdPath) mxdName = os.path.basename(mxdPath)[0:-4] mxdDir = os.path.dirname(mxdPath) pkgPath = os.path.join(mxdDir, mxdName + ".mpk") print "Package Path {0}".format(pkgPath) #Check to see if package already exists and delete, then create map package if os.path.exists(pkgPath): os.remove(pkgPath) print "Succesfully deleted existing package: {0}".format(pkgPath) arcpy.PackageMap_management(mxdPath, pkgPath, extent=rectangle_geometry) #Open new email in Outlook and attach the Map Package outlook = win32com.client.Dispatch("Outlook.Application") email = outlook.CreateItem(0) email.Subject = "Map Package Area of Interest" email.Attachments.Add(pkgPath) email.Display()
Solved! Go to Solution.