Assign Domain To Field (Data Management)

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

  • Domain management involves the following steps:

    1. Create the domain using the Create Domain tool.
    2. Add values to or set the range of values for the domain using the Add Coded Value to Domain tool or Set Value For Range Domain tool.
    3. Associate the domain with a feature class using this tool.
  • One attribute domain can be associated with multiple fields in the same table, feature class, or subtype as well as in multiple tables and feature classes.

  • The Input Table parameter accepts feature layers or table views.

Parameters

LabelExplanationData Type
Input 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 that will be assigned a domain.

Field
Domain Name

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

String
Subtype
(Optional)

The subtype code that will be assigned a domain.

String

Derived Output

LabelExplanationData Type
Updated Input Table

The updated input table.

Table View

arcpy.management.AssignDomainToField(in_table, field_name, domain_name, {subtype_code})
NameExplanationData 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 that will be assigned a domain.

Field
domain_name

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

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

The subtype code that will be assigned a domain.

String

Derived Output

NameExplanationData Type
out_table

The updated input table.

Table View

Code sample

AssignDomainToField example (Python window)

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

import arcpy
arcpy.env.workspace = "C:/data"
arcpy.management,AssignDomainToField("montgomery.gdb/Landbase/Parcels", 
                                     "ZONING_S", "ZoningFields", "1: government")
AssignDomainToField 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
 
# Import system modules
import arcpy

# Set the workspace (to avoid having to type in the full path to the data every time)
arcpy.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.management.CreateDomain("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.management.AddCodedValueToDomain(gdb, domName, code, domDict[code])
    
# Process: Constrain the material value of distribution mains
arcpy.management.AssignDomainToField(inFeatures, inField, domName)

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics