In this video, Jennifer Harrison shows how to use nested loops in ArcPy. Learn how to use nested loops to get to data frames, layers, and layer properties in ArcPy, while making use of list functions.
- [Instructor] I'm gonna show how Python loops…can be nested,…which means putting a loop inside another loop.…The indention is what controls the loop structure.…Everything that is inside the loop must be indented…with the same number of spaces.…Here I have a for each loop that contains a for each loop…that contains a for each loop.…I'm gonna write a script to make a list…of all the label classes that are used in the layers…of a map document.…This will involve some nested loops.…
First we'll need to get the map document.…And then we'll need to get the data frames.…And then we'll need to get the layers.…And finally we'll be able to get to the label classes.…I've got a script already written…that does part of the work for us.…This script lists the data frames in a map document.…First it creates the map document object…and saves it to the mxd variable.…Next it uses arcpy.mapping.ListDataFrames…to create the list of data frame objects,…which it saves to the variable list of data frames.…
Finally, it uses a for loop to step through the list…
- Writing and running Python scripts in IDLE
- Making scripts flexible with variables
- Commenting scripts
- Manipulating string data
- Object-oriented programming in Python
- Creating loops
- Reading and writing text files
- Capturing input at runtime
- Documenting your scripts
Skill Level Beginner
1. Python for ArcGIS Basics
2. Strings, Numbers, and Variables
Work with numeric values5m 22s
3. Syntax Rules
4. Manipulating Strings
5. Object-Oriented Programming
6. Using Loops
7. Generate Log Files
8. Input at Run Time
9. Help Documents
Documenting a script1m 59s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.