Assign Domain To Field (Data Management)

License Level:BasicStandardAdvanced

Summary

Sets the domain for a particular field and, optionally, for a subtype. If no subtype is specified, the domain is only assigned to the specified field.

Usage

Syntax

AssignDomainToField_management (in_table, field_name, domain_name, {subtype_code})
ParameterExplanationData Type
in_table

The name of the table or feature class containing the field that will be assigned a domain.

Table View
field_name

The name of the field to be assigned a domain.

Field
domain_name

The name of a geodatabase domain to assign to the field name. Available domains will automatically be loaded.

String
subtype_code
[subtype_code,...]
(Optional)

The subtype code to be assigned a domain.

String

Code Sample

Assign Domain to Field Example (Python Window)

The following Python window script demonstrates how to use the AssignDomainToField function in immediate mode.

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.AssignDomainToField_management("montgomery.gdb/Landbase/Parcels", "ZONING_S", "ZoningFields", "1: government")
Assign Domain to Field Example 2 (Stand-alone Script)

The following script uses the AssignDomainToField function as part of a workflow to create an attribute domain, assign values to the domain, and assign the domain to a field.

# Name: MakeDomain.py
# Description: Create an attribute domain to constrain pipe material values
# Author: ESRI

 
#Import system modules
import arcpy
from arcpy import env
 
try:
    # Set the workspace (to avoid having to type in the full path to the data every time)
    env.workspace = "C:/data"
 
    # Set local parameters
    domName = "Material4"
    gdb = "montgomery.gdb"
    inFeatures = "Montgomery.gdb/Water/Distribmains"
    inField = "Material"
 
    # Process: Create the coded value domain
    arcpy.CreateDomain_management("montgomery.gdb", domName, "Valid pipe materials", "TEXT", "CODED")
    
    #Store all the domain values in a dictionary with the domain code as the "key" and the 
    #domain description as the "value" (domDict[code])
    domDict = {"CI":"Cast iron", "DI": "Ductile iron", "PVC": "PVC", \
                "ACP": "Asbestos concrete", "COP": "Copper"}
    
    # Process: Add valid material types to the domain
    #use a for loop to cycle through all the domain codes in the dictionary
    for code in domDict:        
        arcpy.AddCodedValueToDomain_management(gdb, domName, code, domDict[code])
    
    # Process: Constrain the material value of distribution mains
    arcpy.AssignDomainToField_management(inFeatures, inField, domName)
 
except Exception, e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
11/18/2013