Why is my script running fine with one feature class but does not run correctly with multiple feature classes?

741
3
Jump to solution
10-25-2016 02:56 PM
TravisPreston2
New Contributor II

The purpose of the script is to count the number of single family homes within each "FireBoxMap" feature class. When I specify a single feature class in line 10 the script runs fine. When I change the feature class to "FireBoxMap*" to run through all of the feature classes it does not populate the desired information. I am not sure what I am doing wrong. 

Thank You

0 Kudos
1 Solution

Accepted Solutions
LesiMai3
Occasional Contributor

Travis,

You may want to move lines 22-24 in front of the for statement and wrap lines 26-37 inside the for statement.

Lesi

View solution in original post

3 Replies
LesiMai3
Occasional Contributor

Travis,

You may want to move lines 22-24 in front of the for statement and wrap lines 26-37 inside the for statement.

Lesi

JonathanQuinn
Esri Frequent Contributor

If you print fcBoxZones after running arcpy.ListFeatureClasses, does the list appear correct?

0 Kudos
LukeWebb
Occasional Contributor III

The question is already answered, but I will write a bit more detail to hopefully help you understand:

You have a "For" Loop, but inside the loop you only have the lines of code: 

print fc
# Add two fields to hold the results
arcpy.AddField_management (fc, "SFCount", "LONG")
arcpy.AddField_management (fc, "MFCOUNT", "LONG")

The rest of the code is not indented, so does not get included in the loop!

So your script currently works as follows:

For each FC:

      print FC

      add fields to FC

On the last FC in the loop only:

selection  + calculate

To fix, simply indent all code after your "For" loop