table to domain: iteration of file geodatabases

309
1
10-26-2011 11:11 AM
PeterWilson
Occasional Contributor III
I'm looking for assistance in adding an attribute domain to multiple file geodatabases by iterating through a folder and adding an attribute domain using "table to domain" for each file geodatabase found within the directory. If anyone can assist me with generating a model within modelbuilder to accomplish this, it will truly be appreciated.

Regards
0 Kudos
1 Reply
JakeSkinner
Esri Esteemed Contributor
Hi Peter,

It may be easiest to do this using a python script rather than model builder. Here is an example on how to do this. The below script will iterate through each sub directory in your 'H:\Projects\H107039_PeterW\workpackages' workspace:

import arcpy, os
from arcpy import env

folder = r"H:\Projects\H107039_PeterW\workpackages"

for (path, dirs, files) in os.walk(folder):
    if ".gdb" not in path.lower():
            env.workspace = path
            databases = arcpy.ListWorkspaces("*", "FileGDB")
            for database in databases:
                arcpy.TableToDomain_management(r"C:\TEMP\Python\domain.dbf", "Code", "Desc", database, "City")


You will just need to update the line "arcpy.TableToDomain_management(r"C:\TEMP\Python\domain.dbf", "Code", "Desc", database[0], "City")". The first variable is the path to the table containing the domain. The second variable is the field containing the domain code. Third variable is the field containing the domain description, and the 5th variable is what you would like to name the domain.
0 Kudos