4

In an effort to try to add user input to my project, I'm developing an esri python addin to generate rectangles to my map. I'm on step one now, just exploring the addin functionality.

I tried making an addin 'tool' precisely per the ESRI sample code, but the button isn't working. It appears on my ArcMap desktop, but when I click it, nothing happens.

I just really want to know what's happening with the onRectangle, and how I can get it to accept user input.

Here's the sample code that I essentially stole from ESRI:

import arcpy
import pythonaddins

class fishnetsExample(object):
    def __init__(self):
        self.enabled = True
        self.cursor = 3
        self.shape = 'Rectangle'

    def onRectangle(self, rectangle_geometry):
        """Occurs when the rectangle is drawn and the mouse button is released.
        The rectangle is a extent object."""
        extent = rectangle_geometry
        # Create a fishnet with 10 rows and 10 columns.
        if arcpy.Exists(r'in_memory\fishnet'):
            arcpy.Delete_management(r'in_memory\fishnet')
        fishnet = arcpy.CreateFishnet_management(r'in_memory\fishnet',
                            '%f %f' %(extent.XMin, extent.YMin),
                            '%f %f' %(extent.XMin, extent.YMax),
                            0, 0, 10, 10,
                            '%f %f' %(extent.XMax, extent.YMax),'NO_LABELS',
                            '%f %f %f %f' %(extent.XMin, extent.YMin, extent.XMax, extent.YMax), 'POLYGON')
        arcpy.RefreshActiveView()
        return fishnet

1 Answer 1

2

Looks correctly set up to me on the Python end. Make sure it's set up to be a Tool and not a Button in the wizard? Once you've confirmed it's set up right, go ahead and try installing the .esriaddin again.

In ArcMap, you'll click on the tool's button in the toolbar, it should appear pressed, at which point you can start clicking and dragging in the map to select extent rectangles. Open the Python window before using it to see if any error messages are sent to it, and any print statements in an event handler in a Python add-in will also go to the Python window so you should be able to add prints in your code to make sure it's getting activated and called.

1
  • Thanks! I knew the code was right, but I ended up saving two versions because I 'saved as' instead of saved my script, and it wasn't working. Human error is the most pernicious of them all. Oct 30, 2013 at 0:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.