I am trying to create a functional add-in button that calculates the areas of a selected shapefile. The code is located below. However, when I create the add-in and bring up the toolbar, I can only see a red circle with a cross, and the word [MISSING]. There is no button to click. Is this an issue with my code?

I have another add-in installed (not ESRI created) that has many buttons, and these all seem to work fine. They were made using the same method (arcgis add.in installer).

import arcpy
import pythonaddins

class CalculateArea(object):
    """Implementation for CalculateArea.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
## Set parameters

        mxd = arcpy.mapping.MapDocument("CURRENT")
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        layers = arcpy.mapping.ListLayers(mxd, "*", df)
        arcpy.env.overwriteOutput = False
        SelectedLayer = pythonaddins.GetSelectedTOCLayerOrDataFrame()
        f_name = "Area_ha"
        f_type = "DOUBLE"
        f_precision = 5
        f_scale = ""
        f_length = ""
        f_alias = ""
        f_null = "NULLABLE"
        f_required = "NON_REQUIRED"
        f_domain = ""

## Create Area field, calculate area in hectares.
        arcpy.AddField_management(SelectedLayer, f_name, f_type, 
f_precision, f_scale, f_length, f_alias, f_null, f_required, f_domain)
        areaexpression1 = "{0}".format("!SHAPE.area@HECTARES!")
        arcpy.CalculateField_management(SelectedLayer, f_name, 
areaexpression1, "PYTHON_9.3", "")
  • Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. Do you have other Add-Ins installed? Are they working correctly? I have seen this before, however it affected almost all my add-ins (all add-ins that were not Esri created). Mine were also .Net add-ins not Python add-ins – Midavalo Apr 13 '17 at 15:02

This happens when the add-in encounters errors on initialisation. If you have the Python window open before loading your toolbar any exceptions will be reported there and should point you in the right direction. You should also check out the Debugging Python Add-ins documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.