Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer
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
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 posting your answer, you agree to the privacy policy and terms of service.

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