Add-in Combo box error

4813
6
Jump to solution
02-12-2015 06:32 AM
Pierre-LucBoivin
Occasional Contributor

Hi,

When I try to install the toolbar with the Combo box, I have this error :

File "<string>", line 1

SyntaxError: can't assign to operator

Usually i'm able to resolve the syntax error but I have no clue for this one.

Here my code :

import arcpy
import pythonaddins

class LayersComboBoxClass(object):
    """Implementation for Python_Add-In_addin.combo_box (ComboBox)"""
    def __init__(self):
        self.items = []
        self.editable = False
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWWWWWWWWWWWWWWWW'
    def onSelChange(self, selection):
        layer = r"S:\Geomatique\Pierre-Luc\SPVM\Corridors_Scolaire\Carto.gdb\Ecoles"
        arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", "DESC_LIEU = '" + selection + "'")
        arcpy.RefreshActiveView()       
    def onEditChange(self, text):
        pass
    def onFocus(self, focused):
        self.mxd = arcpy.mapping.MapDocument('current')
        layer = arcpy.mapping.ListLayers(self.mxd, "Ecoles")[0]
        #self.items = []
        values = [row[0] for row in arcpy.da.SearchCursor(layer, ["DESC_LIEU"])]
        for uniqueVal in sorted(set(values)):
            self.items.append(uniqueVal) 
    def onEnter(self):
        pass
    def refresh(self):
        pass

Thanks for your help

0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Pierre-Luc,

I believe the problem may be that you are trying to pass a feature class to the SelectLayerByAttribute function.  This requires a feature layer.  Try the following:

def onSelChange(self, selection): 
        layer = r"S:\Geomatique\Pierre-Luc\SPVM\Corridors_Scolaire\Carto.gdb\Ecoles"
        arcpy.MakeFeatureLayer_management(layer, "fLayer")
        arcpy.SelectLayerByAttribute_management("fLayer", "NEW_SELECTION", "DESC_LIEU = '" + selection + "'") 
        arcpy.RefreshActiveView()

View solution in original post

0 Kudos
6 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Pierre-Luc,

I believe the problem may be that you are trying to pass a feature class to the SelectLayerByAttribute function.  This requires a feature layer.  Try the following:

def onSelChange(self, selection): 
        layer = r"S:\Geomatique\Pierre-Luc\SPVM\Corridors_Scolaire\Carto.gdb\Ecoles"
        arcpy.MakeFeatureLayer_management(layer, "fLayer")
        arcpy.SelectLayerByAttribute_management("fLayer", "NEW_SELECTION", "DESC_LIEU = '" + selection + "'") 
        arcpy.RefreshActiveView()
0 Kudos
Pierre-LucBoivin
Occasional Contributor

Hi Jake,

That was a good point for the feature layer but I still have the same error even after the modification.

Thanks you

0 Kudos
BenBrosius
New Contributor

I get the same exact error with the default python script with no modifications when I add a combo box.

0 Kudos
Pierre-LucBoivin
Occasional Contributor

Hi Ben !!

I'm always having this error displaying in the python windows on the first line when I loaded my toolbar but I'm able to execute my function anyways.

Good luck

0 Kudos
BenBrosius
New Contributor

Yes will testing I can see that the toolbar still executes but my combo boxes and button all show up as missing so I can't really execute it the way I want to.

I've actually found that if I create a simple toolbar with one button with the wizard and immediately build and install it with no code I get the same error and behavior.

0 Kudos
by Anonymous User
Not applicable

Hey,

a bit late but the problem is not in your code, it's in the filename. Your filename probably contains a dash/hyphen '-' or something else python interpreters don't like. Removing the dash/hyphen should solve your problem. You should also take a look at PEP 8 -- Style Guide for Python Code | Python.org | Naming Conventions.

SyntaxError: 'Add-Ins_addin.py'

OK: 'add_ins_addin.py'

0 Kudos