Add-In button not working

2984
2
05-07-2015 04:35 PM
ChrisPedrezuela
Occasional Contributor III

Hi guys,

I'm new in creating add-ins and just trying to give it a shot. Currently the simple one I setup is not working for me. Basically the user enters an ID, then the button when clicked should change the definition query of a layer and the dataframe changes its extents to this lyr's extents. Just wanted to know where I went wrong. thanks,

import arcpy
import pythonaddins

class EnterQPIDNumberCBox(object):
    """Implementation for CreateQPIDMapExtent_addin.eqncombobox (ComboBox)"""
    def __init__(self):
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWWWWWW'
        self.width = 'WWWWWWWWWW'
    def onSelChange(self, selection):
        pass
    def onEditChange(self, text):
        global id_input
        id_input = int(text)
    def onFocus(self, focused):
        pass
    def onEnter(self):
        self.items.append(id_input)
        pass
    def refresh(self):
        pass

class QPIDToolsExt(object):
    """Implementation for CreateQPIDMapExtent_addin.qpextension (Extension)"""
    def __init__(self):
        # For performance considerations, please remove all unused methods in this class.
        self.enabled = True
    def activeViewChanged(self):
        pass
    def contentsChanged(self):
        pass

class ZoomToPropertyButton(object):
    """Implementation for CreateQPIDMapExtent_addin.ztpbutton (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        mxd = arcpy.mapping.MapDocument('CURRENT')
        df =  arcpy.mapping.ListDataFrames(mxd)[0]
        lyr = arcpy.mapping.ListLayers(mxd, '#', df)[0]
        lyr.definitionQuery = "ID={0}".format(id_input)
        ext = lyr.getExtension()
        df.extent = ext
        arcpy.RefreshActiveView()

Tags (3)
0 Kudos
2 Replies
Luke_Pinner
MVP Regular Contributor

It would help if you could describe exactly *what* is not working and provide any python exceptions you are getting (hint: if you have the ArcMap python window open, any exceptions raised by your addin will be visible).

0 Kudos
ChrisPedrezuela
Occasional Contributor III

Hi Luke. There's actually no error. And I think I've made the button click event working, I've changed it to,

def onClick(self):

        mxd = arcpy.mapping.MapDocument('CURRENT')

        df =  arcpy.mapping.ListDataFrames(mxd)[0]

        lyr = arcpy.mapping.ListLayers(mxd, '#', df)[0]

        lyr.definitionQuery = "ID={0}".format(id_input)

        ext = lyr.getExtension()

        df.panToExtent = ext

0 Kudos