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
Solved! Go to Solution.
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()
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()
Hi Jake,
That was a good point for the feature layer but I still have the same error even after the modification.
Thanks you
I get the same exact error with the default python script with no modifications when I add a combo box.
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
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.
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'