From the course: Learning ArcGIS Python Scripting

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Nested loops

Nested loops

- Let me show you how Python loops can be nested, which means putting a loop inside another loop. The indention is what controls the loop structure. Everything that's inside the loop must be indented with the same number of spaces. I'm going to write a script to make a list of all the label classes used in the layers of a map. This will involve some nested loops because I'm going to have to loop through the layers and then loop through the label classes for each layer. Let's review the steps to get to layer objects in a project. First, we'll need to get to the project. We do that with arcpy.mp.ArgGISProject, and then we need to get to the map. We do that with aprx.listMaps where aprx is the object variable, holding the open connection to the project. So aprx.listMaps and then we need to get the layers. We do that with the list layers method of the map object. And then finally, we need to get to the label classes. And you do that with the list label classes method of the layer object…

Contents