How to loop through layers in map and find certain layers

3438
2
02-21-2017 07:05 AM
MarcosMendez
New Contributor III

Hi,

I was recently given a python test/exercise at work. I'm not sure how to start this particular exercise so if anyone has any suggestions or a sample recipe/code, I would really appreciate it if you can share it with me.

The exercise I was given is:

I have two layers in my mxd which I'll be working off of which are a CITY LAYER and a SEWER MANHOLE LAYER

1.) Loop through layer in map and find the manhole layer and the city layer

2.) Cursor through each record in the city layer

3.) Print city name and how many manholes are within each city layer.

Tags (4)
0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus

If you can do the task manually, using tools in Arctoolbox, you can throw the workflow tools into modelbuilder and spit out a script snippet that will give you the foundations for a full-fledged script.

MitchHolley1
MVP Regular Contributor

This will get you started: 

1.) Loop through layers: ListLayers— ArcGIS for Desktop 

2.) Search through layer attributes: SearchCursor— ArcGIS Desktop 

   a.) I would store data in a list []

3.) Print data in script tool (arcpy.AddMessage) or print in Python IDLE (print ...)