Python Button Add In, onClick function

6832
3
07-15-2013 12:10 PM
adinafurey
New Contributor
Hello,
I am trying to get a simple python code of when I click the button on my combobox toolbar, the button will direct the user to the next page in my Index(Map sheets).
This is my full code. I am only unable to get the onClick portion to not work, but I am very new at this so it could be affecting the rest of the code!

Any help would be greatly appreciated!
Thanks!
import arcpy
import pythonaddins

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
Layer = arcpy.mapping.ListLayers(mxd, "Index_2500", df)[0]
arcpy.SelectLayerByAttribute_management(Layer,"CLEAR_SELECTION")

class ButtonClass2(object):
    """Implementation for Index_addin.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False

    def onClick(self):            
        arcpy.SelectLayerByAttribute_management(Layer,"CLEAR_SELECTION")
        Next = combobox.value + 1
        if len(Next) >=1:
            arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", + Next)
        else:
            pass
        df.zoomToSelectedFeatures()
        arcpy.RefreshActiveView()

class ComboBoxClass1(object):
    """Implementation for Index_addin.combobox (ComboBox)"""
    def __init__(self):
         if arcpy.mapping.ListLayers(mxd, "Index_2500") == []:
            self.enabled = False
         else:
           self.editable = True
           self.enabled = True
           self.width = 'WWWWWW'
    def onSelChange(self, selection):
        pass
    def onEditChange(self, text):
        if len(text) >=1:
            arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", "Page = '" + text + "'")
        else:
            pass
                                              
    def onEnter(self):
        df.zoomToSelectedFeatures()
        arcpy.RefreshActiveView()
        text == ""
        combobox.refresh()
Tags (2)
3 Replies
ToddUlery
Occasional Contributor

Hi Adina,
I am going to help you work through this.


I am just saw this cross my screen and want to take a look at this later. So currently this does not help you, but I will come back and assist. Promise!

I have done similar work with python add ins in the past. I can share my technique with combobox and data driven pages.

0 Kudos
ToddUlery
Occasional Contributor

First off, can I just ask what the error might be. When the python window is open.

0 Kudos
LukeWebb
Occasional Contributor III

If it crashes on this line:

            arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", + Next)

Its because    + Next   (An Integer only)  is not a valid SQL query. It looks much better further down:

arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", "Page = '" + text + "'")

0 Kudos