Last active
August 29, 2015 14:16
-
-
Save cindygis/1446158c59cd9c574e20 to your computer and use it in GitHub Desktop.
Adds a new field and assigns an existing domain to a feature class, or assigns the domain only if the field exists.
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. | |
# | |
import arcpy | |
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(): | |
try: | |
arcpy.management.AddField(in_table=fc, | |
field_name=field_nam, | |
field_type="SHORT", | |
field_alias=field_nam, | |
field_domain=cvd) | |
print("Added field and assigned domain to " + fc) | |
except: | |
print("Field exists in " + fc) | |
arcpy.management.AssignDomainToField(in_table=fc, | |
field_name=field_nam, | |
domain_name=cvd) | |
print("Domain assigned to " + fc) | |
print("Script complete.") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment