AnsweredAssumed Answered

Python Add-In problems

Question asked by TomGeo on Mar 13, 2013
Latest reply on Apr 4, 2013 by nqazi
Hi everybody,

I was just watching the introduction to Desktop Add-Ins using Python and was trying to create the exact same add-in shown in the video. I can't find any flaws in the code I have written and the Add-In was created and installed without any problem. The toolbar is there and the button with the icon on it as well.
When I click the button the cursor is changing to the cursor type specified in the code and I can draw a rectangle on the map canvas. However, there is nothing shown that the system is busy creating the map package and there is non produced. Needless to say that Outlook does not open a new email...

The code to define the function you can find below and it would be nice if you can tell why it does not work.

On the account of not working... There is an import of module 'pythonaddins' and I get it marked as an unresolved import (that's in Eclipse/PyDev). Also when I use the Python shell, importing that particular module results in 'ImportError: No module named pythonaddins'

Cheers Thomas

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()