AnsweredAssumed Answered

Add-In button not working

Question asked by thanos_cp78 on May 7, 2015
Latest reply on May 8, 2015 by thanos_cp78

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

Outcomes