I am building an addin combobox. The combobox will populate a list of all the layers that are in the TOC in ArcMap upon initialization of ArcMap. The user will choose a layer and some actions will take place.
What I want to do is have the comobox listen to the Table of Contents and update any time the user adds or removes a layer automatically. Is this possible?
Thanks
Solved! Go to Solution.
You would need to implement both the ComboBox and an Application Extension. The Application Extension would need to listen for changes in the TOC and you'd need to build a hook to feed the values to the ComboBox. I haven't tested it, but I'm thinking it'd look something like this.
import arcpy import pythonaddins class ComboBoxClass(object): """Implementation for ComboBox""" def __init__(self): self.items = list() self.editable = self.enabled = True self.dropdownWidth = self.width = 'WWWWWW' ComboBoxClass._hook = self class ExtensionClass(object): """Implementation for Application Extension """ def __init__(self): self.enabled = True ExtensionClass._hook = self def itemAdded(self, new_item): ComboBoxClass._hook.items.extend([new_item]) def itemDeleted(self, deleted_item): ComboBoxClass._hook.items.remove(deleted_item)
You would need to implement both the ComboBox and an Application Extension. The Application Extension would need to listen for changes in the TOC and you'd need to build a hook to feed the values to the ComboBox. I haven't tested it, but I'm thinking it'd look something like this.
import arcpy import pythonaddins class ComboBoxClass(object): """Implementation for ComboBox""" def __init__(self): self.items = list() self.editable = self.enabled = True self.dropdownWidth = self.width = 'WWWWWW' ComboBoxClass._hook = self class ExtensionClass(object): """Implementation for Application Extension """ def __init__(self): self.enabled = True ExtensionClass._hook = self def itemAdded(self, new_item): ComboBoxClass._hook.items.extend([new_item]) def itemDeleted(self, deleted_item): ComboBoxClass._hook.items.remove(deleted_item)
HeyFreddie. You have me chasing down a better understanding of hooking in python. I've used your example and modified it a bit. This worked well. Thanks for the input.