Add Coded Value To Domain (Data Management)

License Level:BasicStandardAdvanced

Summary

Adds a value to a domain's coded value list.

Usage

Syntax

AddCodedValueToDomain_management (in_workspace, domain_name, code, code_description)
ParameterExplanationData Type
in_workspace

The geodatabase containing the domain to be updated.

Workspace
domain_name

The name of the attribute domain that will have a value added to its coded value list.

String
code

The value to be added to the specified domain's coded value list.

String
code_description

A description of what the coded value represents.

String

Code Sample

AddCodedValueToDomain Example (Python Window)

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

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.AddCodedValueToDomain_management("montgomery.gdb", "material", "1", "PVC")
AddCodedValueToDomain Example 2 (stand-alone script)

This stand-alone script uses the AddCodedValueToDomain function as part of a workflow to create an attribute domain and give it values.

# 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
5/7/2015