Recently, I wrote a script to quickly add a new field to dozens of feature classes and assign a pre-existing coded value domain to it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|# @date 25/02/2015|
|# @author Cindy Williams|
|# Adds a new field to feature classes in a file GDB|
|# and assigns an existing domain to it. If the field|
|# exists, only the domain is assigned.|
|# For use in the Python window in ArcCatalog.|
|arcpy.env.workspace = r"C:\Some\Arb\Folder\work.gdb"|
|# Input variables|
|cvd = "cvd_District" # Name of existing coded value domain|
|field_nam = "District" # Name of new field to be added to feature class|
|for fc in arcpy.ListFeatureClasses():|
|print("Added field and assigned domain to " + fc)|
|print("Field exists in " + fc)|
|print("Domain assigned to " + fc)|
However, some of the feature classes already contained the field, which is why all the action happens within a try-except block.