3

I am coding an addin to allow me to use 3 comboboxes to select specific regions within a state. Once these are all selected in the comboboxes I need a final button to zoom to the selected area, indicated by the comboboxes. I am not sure how to get the selections from the three comboboxes to all be passed on to the zoom button so that it will zoom to the correct selected region.

Below is my code:

import arcpy
import pythonaddins
class SectionComboBoxClass35(object):
 """Implementation for SEC_TWN_RNG_2_addin.combobox (ComboBox)"""
 def __init__(self):
 self.items = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10" ,"11", "12", "13", "14",
 "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31",
 "32", "33", "34", "35", "36"]
 self.editable = True
 self.enabled = True
 self.dropdownWidth = 'WWWWWW'
 self.width = 'WWWWWW'
 def onSelChange(self, selection):
 pass
 def onEditChange(self, text):
 pass
 def onFocus(self, focused):
 pass
 def onEnter(self):
 pass
 def refresh(self):
 pass
class TownshipComboBoxClass36(object):
 """Implementation for SEC_TWN_RNG_2_addin.combobox_1 (ComboBox)"""
 def __init__(self):
 self.items = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14",
 "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
 "31","32", "32", "33", "34", "35"]
 self.editable = True
 self.enabled = True
 self.dropdownWidth = 'WWWWWW'
 self.width = 'WWWWWW'
 def onSelChange(self, selection):
 pass
 def onEditChange(self, text):
 pass
 def onFocus(self, focused):
 pass
 def onEnter(self):
 pass
 def refresh(self):
 pass
class TownshipDirectionComboBoxClass37(object):
 """Implementation for SEC_TWN_RNG_2_addin.combobox_2 (ComboBox)"""
 def __init__(self):
 self.items = ["N", "S", "E", "W"]
 self.editable = True
 self.enabled = True
 self.dropdownWidth = 'WWWWWW'
 self.width = 'WWWWWW'
 def onSelChange(self, selection):
 pass
 def onEditChange(self, text):
 pass
 def onFocus(self, focused):
 pass
 def onEnter(self):
 pass
 def refresh(self):
 pass
class RangeComboBoxClass38(object):
 """Implementation for SEC_TWN_RNG_2_addin.combobox_3 (ComboBox)"""
 def __init__(self):
 self.items = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14",
 "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
 "31","32", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45"]
 self.editable = True
 self.enabled = True
 self.dropdownWidth = 'WWWWWW'
 self.width = 'WWWWWW'
 def onSelChange(self, selection):
 pass
 def onEditChange(self, text):
 pass
 def onFocus(self, focused):
 pass
 def onEnter(self):
 pass
 def refresh(self):
 pass
class RangeDirectionComboBoxClass39(object):
 """Implementation for SEC_TWN_RNG_2_addin.combobox_4 (ComboBox)"""
 def __init__(self):
 self.items = ["N", "S", "E", "W"]
 self.editable = True
 self.enabled = True
 self.dropdownWidth = 'WWWWWW'
 self.width = 'WWWWWW'
 def onSelChange(self, selection):
 pass
 def onEditChange(self, text):
 pass
 def onFocus(self, focused):
 pass
 def onEnter(self):
 pass
 def refresh(self):
 pass
class ZoomButtonClass40(object):
 def onClick(self):
 mxd = arcpy.mapping.MapDocument("CURRENT")
 df = arcpy.mapping.ListDataFrames(mxd)[0]
 addLayer = arcpy.mapping.Layer(r'T:\Software\ESRI-GIS\toolbars\sec-twn-rng\KDAGISEDITOR.plss.lyr')
 arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
 """Implementation for Zoom.button (Button)"""
 def __init__(self):
 self.enabled = True
 self.checked = False
 def onClick(self):
 pass
 # Implementation of OnClick method of Button's class
 def onClick(self):
 # Get the current map document and the first data frame.
 mxd = arcpy.mapping.MapDocument('current')
 df = arcpy.mapping.ListDataFrames(mxd)[0]
 # Call the zoomToSelectedFeatures() method of the data frame class
 df.zoomToSelectedFeatures() 
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jan 11, 2016 at 17:23

1 Answer 1

2

You probably are going to want to form a where clause out of the comboboxes. You can get at the value of the combobox by looking at the docstring of your class to get the actual combobox object's value by the name you see there. So in this example:

class RangeComboBoxClass38(object):
 """Implementation for SEC_TWN_RNG_2_addin.combobox_3 (ComboBox)"""
 def __init__(self):
 # stuff

The name of the combobox object is combobox_3, so to get at the value you can simply use combobox_3.value.

So using this knowledge, you can form a where clause with your addLayer variable. I'm just making this up but you could do something like this in your ZoomButtonClass40.onClick() method:

field_name = 'SEC' # name of field to search 
delimited = arcpy.AddFieldDelimiters(addLayer, field_name)
where = '{} = {}{}'.format(delimited, combox_2.value, combobox_3.value) #concatenate the values of combobox_2 and combobox_3
arcpy.management.SelectLayerByLocation(addLayer, 'NEW_SELECTION', where)
df.zoomToSelectedFeatures() 
answered Jan 11, 2016 at 18:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.