Select to view content in your preferred language

How to iterate multiple Gdb's and their Feature classes to add fields into each of them?

824
3
04-13-2023 09:20 AM
AmyKou
by
New Contributor

I created 3 gdb's under the home project gdb and created 3 point feature classes in each respectively. How do I iterate through all the file gdb's and add fields into each of them?

LGIM scrip gdbs.png

LGIM script.png

Tags (3)
0 Kudos
3 Replies
AlfredBaldenweck
MVP Regular Contributor

Give Add Fields a shot Add Fields (multiple) (Data Management)—ArcGIS Pro | Documentation, especially if you batch it in the GUI. (Right click, "Batch"). If you only have three (or even 9) feature classes, this is gonna be the easiest way to do it.

RhettZufelt
MVP Notable Contributor

You need a list of workspaces to iterate, in your current code, 'workspaces' is not defined.

So, set the folder that contains them to arcpy.env.workspace = "path:to/workspaces/folder",  then workspaces = arcpy.ListWorkspaces("*", "FileGDB"), OR, manually make the list of workspaces.

Then, you need to move the featureclasses = arcpy.ListFeatureClasses()  into the for workspace loop.

Need to set the workspace first so it can list the featureclasses in that workspace.

The rest of the code looks good.

R_

0 Kudos
ZacharyUhlmann1
Frequent Contributor

@RhettZufelt is correct.  You need this:

workspaces = ['path/to/workspace1','path/to/workspace2','path/to/workspace3']

That's step 1.  There are more steps after that to fix your code.  If you are still needing help on this, please respond and I (we) can help you.

0 Kudos