From the course: Learning ArcGIS Python Scripting (2018)

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Use the foreach loop

Use the foreach loop - ArcGIS Tutorial

From the course: Learning ArcGIS Python Scripting (2018)

Start my 1-month free trial

Use the foreach loop

- [Instructor] A list loop loops through a list of values, executing a section of code once for each value in the list. This type of loop is especially powerful when working with ArcGIS and GIS data. Because ArcPy has a set of list functions, they return lists of things so the for loop can easily execute code on that list. The ArcPy list functions can list FeatureClasses, Layers, BrokenDataSources, DataFrames, and even Files in a workspace. I'm in IDLE and I have a script that I've already started here. I'll use this to demonstrate how to use a list to work through the return elements from a list function in ArcPy. I'll write a script that lists out all of the layers in a map document. First, I'll need to import the ArcPy module. Next, I'll instantiate the map document object. I'll touch the map document and make an open connection to it. I'll use an mxd variable. That's just a name I chose, mxd, to hold the map document object. You create the map document object by using the…

Contents