HOW TO
There can be multiple add-in combo boxes in a project and in some cases, it may be desirable to have two or more combo boxes to mirror one another. In a project, more items can be added to a combo box add-in along the process. If there are other combo boxes mirroring the currently edited combo box, it is desirable for the other combo boxes to copy the items dynamically. This is possible using the onSelChange(self selection) method.
The following steps demonstrate how to dynamically add items into a Python add-in combo box from another add-in combo box:
import arcpy import pythonaddins
class cbxClass1 (object):
class cbxClass2 (object):
def __init__(self): self.items = [chr(n) * 3 for n in range(65, 65+3)] # [AAA, BBB, CCC] self.editable = True self.enabled = True self.dropdownWidth = 'WWWWWW' self.width = 'WWWWWW' cbxClass1._hook = self
def __init__(self): self.items = [chr(n) * 4 for n in range(90, 90 - 3, -1)] # [ZZZ, XXX, YYY] self.editable = True self.enabled = True self.dropdownWidth = 'WWWWWW' self.width = 'WWWWWW' cbxClass2._hook = self
def onSelChange(self, selection): cbxClass2._hook.items.extend([selection])
def onSelChange(self, selection): cbxClass1._hook.items.extend([selection])The following is a sample of a full code.
import arcpy import pythonaddins class cbxClass1(object): """Implementation for ComboBoxExample_addin.cbx1 (ComboBox)""" def __init__(self): self.items = [chr(n) * 3 for n in range(65, 65+3)] # [AAA, BBB, CCC] self.editable = True self.enabled = True self.dropdownWidth = 'WWWWWW' self.width = 'WWWWWW' cbxClass1._hook = self def onSelChange(self, selection): cbxClass2._hook.items.extend([selection]) class cbxClass2(object): """Implementation for ComboBoxExample_addin.cbx2 (ComboBox)""" def __init__(self): self.items = [chr(n) * 4 for n in range(90, 90 - 3, -1)] # [ZZZ, XXX, YYY] self.editable = True self.enabled = True self.dropdownWidth = 'WWWWWW' self.width = 'WWWWWW' cbxClass2._hook = self def onSelChange(self, selection): cbxClass1._hook.items.extend([selection])
Article ID: 000017679
Get help from ArcGIS experts
Download the Esri Support App