I am working with arcpy 10.3 and i want to build a add-in. Unfortunately it's not working when i add a button like:

import arcpy
import pythonaddins

class ButtonClass1(object):
    """Implementation for my ad_addin.button (Button)"""
def __init__(self):
    self.enabled = True
    self.checked = False
def onClick(self):
    pythonaddins.MessageBox("test","test_button", 0)

It shows the button but nothing happens! Also when i try to add a new button its not there! how i do this: True python add-in wizard i add a button to the toolbar and press save. Then in the python add-in wizard i press open folder and go to the instal folder and edit my code. Save it. Run makeaddin.py and instal my addin.

I dont see wats the problem!

closed as off-topic by PolyGeo Apr 15 '16 at 4:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Check and make sure your __init__() and onClick() methods are indented. – Ken Apr 11 '16 at 13:51
  • While i tried the add-in the second time with the second button added i also re-started ArcGIS... – Kim Duyvejonck Apr 11 '16 at 13:52
  • Yes they are! everything exept the pythonaddins.MessageBox("test","test_button", 0) is created by the add-in wizard! – Kim Duyvejonck Apr 11 '16 at 13:56
  • Every time you save in the Add-In wizard it creates a new addin python file. The addin tool only uses the one without the number suffix (e.g. _1). Could you be editing the wrong file? Just a thought... – dslamb Apr 11 '16 at 14:09
  • @dslamb Indentations look fine, so is the rest off the code. what i think it could be is some background process or something! because my pc is just new and maybe something is not installed right or missing? – Kim Duyvejonck Apr 12 '16 at 6:07

I ran a test for this and it works fine if there are no bugs in the code. Indentation errors (as @Ken points out) will not show up as an error on the toolbar but the tool won't run. There must be some little error in your python file that isn't being detected.

Your code should resemble this:

import arcpy
import pythonaddins

class ButtonClass1(object):
    """Implementation for buttonTest_addin.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):

My config.xml addin file looks like this:

<ESRI.Configuration xmlns="http://schemas.esri.com/Desktop/AddIns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Name>Python Addin</Name><AddInID>{0a41c482-c5c0-4766-af0c-9c7e30070ad1}</AddInID><Description>New Addin</Description><Version>0.1</Version><Image /><Author>Untitled</Author><Company>Untitled</Company><Date>04/11/2016</Date><Targets><Target name="Desktop" version="10.2" /></Targets><AddIn language="PYTHON" library="buttonTest_addin.py" namespace="buttonTest_addin"><ArcMap>
        <Button caption="Button" category="Python Addin" class="ButtonClass1" id="buttonTest_addin.button" image="" message="" tip=""><Help heading="" /></Button>
        <Toolbar caption="Toolbar" category="Python Addin" id="buttonTest_addin.toolbar" showInitially="true"><Items><Button refID="buttonTest_addin.button" /></Items></Toolbar>

And my makeaddin.py file looks like this:

import os
import re
import zipfile

current_path = os.path.dirname(os.path.abspath(__file__))

out_zip_name = os.path.join(current_path, 
                            os.path.basename(current_path) + ".esriaddin")

BACKUP_FILE_PATTERN = re.compile(".*_addin_[0-9]+[.]py$", re.IGNORECASE)

def looks_like_a_backup(filename):
    return bool(BACKUP_FILE_PATTERN.match(filename))

with zipfile.ZipFile(out_zip_name, 'w', zipfile.ZIP_DEFLATED) as zip_file:
    for filename in ('config.xml', 'README.txt', 'makeaddin.py'):
        zip_file.write(os.path.join(current_path, filename), filename)
    dirs_to_add = ['Images', 'Install']
    for directory in dirs_to_add:
        for (path, dirs, files) in os.walk(os.path.join(current_path,
            archive_path = os.path.relpath(path, current_path)
            found_file = False
            for file in (f for f in files if not looks_like_a_backup(f)):
                archive_file = os.path.join(archive_path, file)
                print archive_file
                zip_file.write(os.path.join(path, file), archive_file)
                found_file = True
            if not found_file:
                                  "(Empty directory)")

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