I have a script that uses a arcpy's 'SelectByAttribute' syntax to choose a record in a polygon feature class. Following that, I do a 'SelectbyLocation' to select points from a feature class that lie within the selected polygon. I do some processing on the points afterwards.

What I want to know is, can I somehow use the 'Select Features' tool from the 'Tools' toolbar to select the polygon and then use that selection to pass into a python addin button instead of using the 'SelectByAttribute' noted above? I hope this makes sense. I'm new to python addins.


Whenever you run Python tools from within ArcMap and reference layers from the Table Of Contents as an input to a geoprocessing tool, it honors current selections, and will ignore unselected features. So your script should only select points that intersect currently selected polygons.

Note that this functionality will not work when executing Python scripts from outside of ArcMap.

  • Thanks dmahr. I did not realize this. I adjusted my script (removed the 'SelectByAttribute' syntax), installed the addin and opened up a map with a polygon and point feature class. I selected a polygon, ran my button and it worked!
    – Mike
    Jul 31 '12 at 21:15
  • 1
    Glad to hear it Mike! I've clarified the answer a bit so people know that this will not work from outside of ArcMap.
    – dmahr
    Jul 31 '12 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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