-1

I want the user to be able to click on a feature on a map, and from there have the GIS automate a window that can come up to select features to see if they are in that set distance from the feature. I have been working with python add-ins but I'm a little confused where to integrate the user. This is what I have so far...

class SelectLayerByLocation(object):
    """Implementation for Select_By_Location_addin.tool (Tool)"""
    def __init__(self):
        self.enabled = True
        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):
        distance = #maybe add some dialog box to select this? Not sure how to get a box to add just a linear unit
        mxd = arcpy.mapping.MapDocument("CURRENT")
        pointGeom = arcpy.PointGeometry(arcpy.Point(x, y), mxd.activeDataFrame.spatialReference)
        for lyr in arcpy.mapping.ListLayers(mxd, "", mxd.activeDataFrame):
            if lyr.isFeatureLayer:
                arcpy.SelectLayerByLocation_management(pointGeom, "WITHIN_A_DISTANCE", lyr, distance)
        arcpy.RefreshActiveView()  #also maybe a way to select layers from a some sort of checkbox or dropdown menu?

marked as duplicate by PolyGeo Dec 6 '17 at 22:27

This question was marked as an exact duplicate of an existing question.

  • Don't forget to take the Tour to learn about our focused Q&A format. – PolyGeo Dec 6 '17 at 22:28
  • What happens when you open the tool? Is the tool available to be added onto a toolbar? – Michael Stimson Dec 6 '17 at 22:52
0

You can integrate with the user by using parameters. First you have to define them for the script. Right click the script in the tool box and press properties. Go to the parameters tab and fill in the parameters and the type you want them to be:

enter image description here

Later on you can get them from:

arcpy.GetParameterAsText(0)

0 being the first parameter, etc.

  • Not quite, that's for a python tool not a python Addin. The OP wants to activate a tool, click on a map and select features from the clicked location not open a tool from the toolbox and type in a coordinate. – Michael Stimson Dec 6 '17 at 22:49
  • Ah, sorry I misunderstood – Lennert De Feyter Dec 6 '17 at 23:05
  • @MichaelStimson yes that is what I am looking to do. I have created a template for it, but have not yet had a successful script. I am having difficulty going from the coordinates created in the python add-in to the selection script that I created as a toolbox. – Daniel Katleman Dec 7 '17 at 20:11
  • Have you added the addin to ArcMap with the AddIn Manager? Have you placed the button for your addin onto a toolbar in ArcMap? When you click the button to activate the python addin does it stay clicked (active)? What happens when you click on the map with the addin tool active? This is one place where .NET is much better than python, at this point I would add a breakpoint in the event to ensure the event is being activated, showing it was wired properly. – Michael Stimson Dec 7 '17 at 21:10

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