Select to view content in your preferred language

10.1 addin combobox value

2890
5
Jump to solution
04-23-2012 09:50 AM
KevinBell
Deactivated User
I'm having a bad time getting the value from a combobox.  I thought it should just be something like this:

myText = comboboxName.value

...but I can't seem to get it going.  Any ideas?  Any sample code?!

thanks!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JasonScheirer
Esri Alum
Yeah, you can't use BufferType as that's the class and not the instance of the class that's used, you have to use the value of the combo box's ID as a variable name. So if its ID is defined as
MyNewAddin_addin.somecombobox
in the wizard, you'll use
somecombobox.value
.

View solution in original post

0 Kudos
5 Replies
StacyRendall1
Frequent Contributor
Kevin,

I see you still don't have any answers for this. Can you provide more information with your question? For example: the whole piece of code you are using, the error you are receiving...

I am not familiar with any of the new features in 10.1, but in 10 you get values from inputs (including, I presume, comboboxes) via arcpy.GetValueAsText(). Or are you using something like Tk?
0 Kudos
KimOllivier
Honored Contributor
Kevin, 

I see you still don't have any answers for this. Can you provide more information with your question? For example: the whole piece of code you are using, the error you are receiving... 

I am not familiar with any of the new features in 10.1, but in 10 you get values from inputs (including, I presume, comboboxes) via   arcpy.GetValueAsText(). Or are you using something like   Tk?


If you have not got 10.1 and are not trying to use the new 10.1 only AddIns module for Python then you cannot help.

I can't work it out either. I assume we have to understand how namespaces in classes work. We have to find the name of the instance of the class which might be that ID that we fill in at the wizard screen.
0 Kudos
JasonScheirer
Esri Alum
Could you post your script? How to get the value of the combobox depends on the context in which you're fetching it.
0 Kudos
KevinBell
Deactivated User
I'm trying to pick from a combobox to get a list of distances for the multibuffer gp tool.  upon clicking the map, the buffers are built.


import arcpy
import pythonaddins


class BufferTool(object):
    """Implementation for MultiBuffer_addin.tool (Tool)"""
    def __init__(self):
        self.enabled = True
        self.cursor = 3

    def onMouseDownMap(self, x, y, button, shift):

        buffers= {"buffer1": [70, 1200], \
       "buffer2": [110, 1700],\
       "buffer3": [150, 1850]}
        
        sr = arcpy.SpatialReference(arcpy.Describe("parcels").spatialReference.factoryCode)
        pt = arcpy.PointGeometry(arcpy.Point(x,y), sr)
        arcpy.env.overwriteOutput = True
        arcpy.env.addOutputsToMap = True
        ptfeat = arcpy.management.CopyFeatures(pt, r"in_memory\pt")
        
        buff = "{0}".format(BufferType.value)
        print buff
        print buffers[buff]
        theBuffers = buffers[buff]
        
        #arcpy.MultipleRingBuffer_analysis(ptfeat, r'in_memory\blastzone', [200, 400]) # works
        arcpy.MultipleRingBuffer_analysis(ptfeat, r'in_memory\blastzone', theBuffers)
        
        arcpy.RefreshActiveView()


class BufferType(object):
    """Implementation for MultiBuffer_addin.distance (ComboBox)"""
    def __init__(self):
        self.hintText = 'buffer type'
        self.items = ["buffer1", "buffer2", "buffer3"]
        self.editable = False
        self.enabled = True
        self.dropdownWidth = 'WWWWWWWWWW'
        self.width = 'WWWWWWWWWW'

    def onSelChange(self, selection):
        print self.value
0 Kudos
JasonScheirer
Esri Alum
Yeah, you can't use BufferType as that's the class and not the instance of the class that's used, you have to use the value of the combo box's ID as a variable name. So if its ID is defined as
MyNewAddin_addin.somecombobox
in the wizard, you'll use
somecombobox.value
.
0 Kudos