Skip to content

Instantly share code, notes, and snippets.

@cindygis
Last active July 21, 2018 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cindygis/5ec6a0b9dae0c89fdd37f68567f51344 to your computer and use it in GitHub Desktop.
Save cindygis/5ec6a0b9dae0c89fdd37f68567f51344 to your computer and use it in GitHub Desktop.
#
# @author Cindy Jayakumar
# @date 21/07/2018
#
# Extract domains from a field in one feature class, and apply
# it to matching fields in another feature class.
#
import arcpy
source_fc = r'C:\Some\Arb\Folder\test.gdb\source'
target_fc = r'C:\Some\Arb\Folder\test.gdb\target'
# Get field names and domains if applicable
source_fields = {field.name : field.domain for field in arcpy.ListFields(source_fc) if field.domain}
for field in arcpy.ListFields(target_fc):
if field.name in source_fields and field.domain is None:
arcpy.management.AssignDomainToField(target_fc, field.name, source_fields[field.name])
print("Assigned {0} to {1}".format(source_fields[field.name], field.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment