Select to view content in your preferred language

Python Add-In Combobox will not populate

2783
5
11-25-2013 11:36 AM
JohnKing
New Contributor
Hi all,

I'm trying to create a simple add-in combo box using the new python interface. I have read the ESRI help on creating an add in project (http://resources.arcgis.com/en/help/main/10.1/index.html#/project/014p00000022000000/) as well as creating an add in combo box (http://resources.arcgis.com/en/help/main/10.1/index.html#/combo_box/014p00000028000000/).

I am having trouble populating the combo box from a list of values that I pass to the __init__ class within the install file.

Here is my entire script:


import arcpy
import pythonaddins

class ComboBoxClass1(object):
    """Implementation for Project Map_addin.combobox (ComboBox)"""
    def __init__(self):
        self.items = ["Project 1", "Project 2", "Project 3", "Project 4"]
        self.editable = False
        self.enabled = True
        self.dropdownWidth = 'WWWWWWWWW'
        self.width = 'WWWWWWWWWWWW'
        self.refresh()

    def onSelChange(self, selection):
        pass
    def onEditChange(self, text):
        pass
    def onFocus(self, focused):
        pass
    def onEnter(self):
        pass
    def refresh(self):
        pass


I have tried a number of different things to get the drop-down to populate. None have worked.

Any suggestions would be great
Tags (2)
0 Kudos
5 Replies
JakeSkinner
Esri Esteemed Contributor
Hi John,

Are you receiving any errors in the python window in ArcMap when you click on the dropdown?

Before installing the add-in, was ArcMap closed?

What is the name of your add-in?
0 Kudos
FredKellner1
Deactivated User
Jskinn3 brings up some good points about installing combo boxes. However, if this is how your code is currently set up your drop down will be populated with the values that you identified in self.items

self.items = ["Project 1", "Project 2", "Project 3", "Project 4"]


here is a snippet from an addin tool bar that I created.

class ListLayers(object):
    """Implementation for NEZ_EDITS_addin.list_layers (ComboBox)"""
    def __init__(self):
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWWWWWWWW'
        self.width = 'WWWWWWWWWWW'
    def onSelChange(self, selection):
  global l
  l=arcpy.mapping.ListLayers(self.mxd, selection)[0]
  arcpy.RefreshActiveView()

    def onFocus(self, focused):
  if focused:
   self.mxd = arcpy.mapping.MapDocument('current')
   layers = arcpy.mapping.ListLayers(self.mxd)
   self.items = []
   for layer in layers:
    self.items.append(layer.name)
    def onEnter(self):
        pass
    def refresh(self):
        pass


This should allow you to populate your combo box with the TOC from your mxd and when selection is made the layer selected becomes a global variable that can be used in any of the other buttons on my toolbar.
0 Kudos
JohnKing
New Contributor
Thanks for the quick responses.

AMJSkinn3: All Arc applications were closed when the add-in was installed. To make sure I uninstalled the add in, recreated the project folder, compiled, and re-installed the add-in. Also, neither the python window nor the results window have any errors to report. When I added the toolbar to ArcMap, the combo box says "[Missing]".

For a quick explanation to what I'm trying to accomplish.. I'd like to select a project name from the combo box. The project name selected will direct a python script to grab specific layers on file with which it will build a project map with correct Data Frame name and Spatial Reference.

I'm trying to solve this issue with the simplest example possible to make sure it is do-able.
0 Kudos
FredKellner1
Deactivated User
If any of the buttons, combo boxes etc. are "missing" there is some type of error with your code perhaps an indent issue or left off bracket. Try opening a mxd, then open the Arc Python Window, and then add your toolbar. Often times when there is a problem with the code in the toolbar you will get an error message in the Arc Python window.
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Thanks for the quick responses.

AMJSkinn3: All Arc applications were closed when the add-in was installed. To make sure I uninstalled the add in, recreated the project folder, compiled, and re-installed the add-in. Also, neither the python window nor the results window have any errors to report. When I added the toolbar to ArcMap, the combo box says "[Missing]".

For a quick explanation to what I'm trying to accomplish.. I'd like to select a project name from the combo box. The project name selected will direct a python script to grab specific layers on file with which it will build a project map with correct Data Frame name and Spatial Reference.

I'm trying to solve this issue with the simplest example possible to make sure it is do-able.


What is the name of the folder directory your add-in is stored in?  It cannot contain spaces.  For example, if the folder directory is called 'Combo Box', you will receive the 'Missing' icon on your toolbar.  Recreate the add-in and make sure there are no spaces in the directory.
0 Kudos