PyScript to Iterate through several GDB in 1 folder

5435
11
11-14-2012 12:58 PM
by Anonymous User
Not applicable
Original User: clarkc5

Okay. I have a rather simple task that I Want to try and automate. Model builder did not seem like the right way to go (I could be wrong and if you think model builder is in fact more appropriate please let me know). So I thought a script would work but need some help. I currently have Several (20) gdb in one folder. In each one of these gdb there is a feature class (Events2HEM). These feature classes all have an attribute field called "HUC_8". This field has different values as you move through all the gdb's. I have now created new gdb's for each value found in the HUC_8 attribute field. I would like to now break up my feature classes into the gdb according to the values found in the HUC_8 field.

FOr example: Older gdb = Fish1.gdb Feature Class is Events2HEM. IN the Huc_8 field lets say we have values of 002, 006, 101, 102. I would like to send anything with value 002 to a new gdb named 002.gdb, and the same for values of 006, 101, 102.

All the new gdb are created already and are located in a new folder. So really I just need a script that will break everything out by the different values found in the HUC_8 field and send them to the corresponding new GDB. The script needs to iterate through 20 gdb found in the old directory.

Here is a photo of the old fodler and gdb, and the new folder and gdb. The new gdb names are values that are found in the HUC_8 field from any if the previous gdb. feature classes. Also there is a picture showing the HUC_8 field with two different values which are found in the Feature class Events2HEM. The feature class is the same through all the different geodatabases, just he HUC_8 values will differ.[ATTACH=CONFIG]19311[/ATTACH]

[ATTACH=CONFIG]19309[/ATTACH]
0 Kudos
11 Replies
ChristopherClark1
Occasional Contributor
Well I could never get past that error, so I went back to model builder. I simply merged all the FeatureClasses together into one FC. Then I used iterate row for the HUC_8 field and was able to group by the values found in this field. I used an inline variable and selected each value with this and exported to a gdb of the same value.

I would still be interested in trouble shooting the python script though.
0 Kudos
by Anonymous User
Not applicable
Original User: msayler-w

Are you running it through ArcMap or ArcCatalog? That link sounds like they were experiencing a quirk of running the tool in ArcMap using python. Had a vaguely similar sort of experience using the SelectLayerByLocation tool. It wants to copy the layer into the active dataframe if it doesn't already exist.

Also, is that append backwards? Are you wanting to append to "fc_lyr" or to "Events2HEM", which I thought was the source feature class?
0 Kudos