AnsweredAssumed Answered

Python Add-in interval counter

Question asked by PNWGIS on Sep 27, 2017
Latest reply on Sep 28, 2017 by PNWGIS

Hi,

 

I am trying to make a Python add-in that a user can click on a parcel and it assigns a taxlot number starting from the combo boxes where users enter the start and the interval.. My problem is the counter function I am using does not work. However, the function works within the Python window in ArcMap. I can assign the taxlot by clicking the taxlot in the map, but the taxlot number does not change after the first. Here is my code:(Is there a better way to post the code?)

 

Thanks for any help.

import arcpy
import pythonaddins

def counter(strt, inter):
        global count
        count = strt
        while True:
            yield count
            count += inter
class ComboBoxClass1(object):
    """Implementation for ClickAttribute_addin.combobox (ComboBox)"""
    def __init__(self):
       
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
    def onSelChange(self, selection):
        pass
    def onEditChange(self, text):
        global start
        mxd=arcpy.mapping.MapDocument('current')
        start = text
    def onFocus(self, focused):
        pass
    def onEnter(self):
        pass
    def refresh(self):
        pass
class ComboBoxClass2(object):
    """Implementation for ClickAttribute_addin.combobox_1 (ComboBox)"""
    def __init__(self):
       
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
    def onSelChange(self, selection):
        pass
    def onEditChange(self, text):
        global interval
        mxd=arcpy.mapping.MapDocument('current')
        interval = text
    def onFocus(self, focused):
        pass
    def onEnter(self):
        pass
    def refresh(self):
        pass

class ToolClass5(object):
    """Implementation for ClickAttribute_addin.tool (Tool)"""
    def __init__(self):
        self.enabled = True
        self.cursor=3
        self.shape = "NONE" # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.
    def onMouseDown(self, x, y, button, shift):
        pass
    def onMouseDownMap(self, x, y, button, shift):
        mxd=arcpy.mapping.MapDocument('current')
        pointGeom = arcpy.PointGeometry(arcpy.Point(x, y), mxd.activeDataFrame.spatialReference)
        lyr = arcpy.mapping.ListLayers(mxd,"Taxlots")
       
      
        arcpy.SelectLayerByLocation_management("Taxlots","INTERSECT",pointGeom,"","NEW_SELECTION")
       
       
    def onMouseUp(self, x, y, button, shift):
        mxd=arcpy.mapping.MapDocument('current')
        lyr = arcpy.mapping.ListLayers(mxd,"Taxlots")
       
        field="Taxlot"
        cursor=arcpy.UpdateCursor("Taxlots")
        for row in cursor:
            row.setValue(field,str(count.next()))
            cursor.updateRow(row)
       
        ComboBoxClass1.value=count.next()
    def onMouseUpMap(self, x, y, button, shift):
        pass
    def onMouseMove(self, x, y, button, shift):
        pass
    def onMouseMoveMap(self, x, y, button, shift):
        pass
    def onDblClick(self):
        pass
    def onKeyDown(self, keycode, shift):
        pass
    def onKeyUp(self, keycode, shift):
        pass
    def deactivate(self):
        pass
    def onCircle(self, circle_geometry):
        pass
    def onLine(self, line_geometry):
        pass
    def onRectangle(self, rectangle_geometry):
        pass

Outcomes