Cannot add coded values to Domains for SDE Enterprise Geodatabase using .py Example

1405
5
09-27-2017 04:56 AM
JordanMiller4
Occasional Contributor III

I'm trying to add coded values to a new created domain using Arcpy in ArcCatalog but I keep getting this strange error. The domain gets created but the coded values generate an error. I used this exact python tool for a local file geodatabase with no issues so I don't understand why there would be problems with an enterprised geodatabase.

Software:

ArcGIS Desktop version: 10.3.1

Enterprise Geodatabase version: 10.3.1

SQL 2012

Code: 

import arcpy
from arcpy import env

domName = "test"
gdb = "GIS.sde"

env.workspace = "C:\Users\jnmiller\AppData\Roaming\ESRI\Desktop10.3\ArcCatalog"
arcpy.CreateDomain_management(gdb, domName, "Test Materials", "TEXT", "CODED")

domDict = {"CI":"Cast iron", "DI": "Ductile iron", "PVC": "PVC", \

                         "ACP": "Asbestos concrete", "COP": "Copper"}

for code in domDict:
            arcpy.AddCodedValueToDomain_management(gdb, domName, code, domDict

)

Error: Why does this list every single domain already created in the database?

Runtime error Traceback (most recent call last): File "<string>", line 10, in <module> File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 1317, in AddCodedValueToDomain raise e ExecuteError: ERROR 000800: The value is not a member of Gas Service Diameter Plastic PVC | Rectifier Manufacturer | Work Order Status | GasASTMF2897CSteelPipeType | Pipe Diameter Plastic PVC | Leak Survey Frequency | ILI Survey Ext Indicator | Pipe Crossing Piped Utility | Gas Service Diameter Plastic PE | Pass Fail | YesNo Indicator with NA | CompanyID | Length Source | HCA Area Class | Pipe Diameter Units | Regulator Casing Material | UnitsForPressure | Leak Cause Material | ExcavDam Damage Type | HCAProvenance | PipelineMarker Condition | ExcavDam Work Type | Pipe Non-Steel Seam Type | Coating Condition | Regulator Body Types | GASASTMF2897Regulator | GasASTMF2897EFV | Item Number Pipe | ControllineManufacturer | GasASTMF2897ComponentMaterial | Method Detected Type | Compressor Station Type | Yes No Indicator | Gas Pipe Diameter Cast Iron | GasASTMF2897PlasticPipeType | Pipe Diameter | Odorizer Manufacturer | Gas Flow | Anomaly Remediation | Soil Type | System Names | Coating Type | PipeGrade | Rectifier Type | Rectifier Cable Gauge | Leak Location | Gas Service Diameter Plastic ABS | Leak Cause | Leak Class | Valve Use Type | GasASTMF2897CouplingType | Pipe Casing Protection Type | Could Affect Intersection Type | Dehydration Method | Pilot Connect Type | Meter Manufacturers | Valve Model | Gas Pipe Manufacturer | Pipe_WallthicknessSteel | Pipe Casing End Connection | Regulator Type | Test Point Type | On Off Status | Pipe Metallic Seam Type | Gas Pipe Diameter Copper | Pipe Facility Status | Wellhead Material Class | Gas Pipe Diameter Plastic ABS | Regulator Manufacturer | Gas Pipe Diameter Wrought Iron | GasASTMF2897Anodes | Leak Survey Work Order Type | Leak Survey Type | GasASTMF2897Elbows | Gas Pipe Diameter Ductile Iron | Pipe Casing Reason | Surface Type | Leak Cause Corrosion | Leak Facility Type | Leak Closed Status | Meter Type | Leak Method Detected Type | Marker Type | ExcavDam Root Cause | Item Number EFV | PipeWallThickness | Pipe Type | Gas Service Diameter Coated Steel | Operating Status | GasASTMF2897_Manufacturer | Anomaly Priority | Fitting Manufacturer | Document Maturity Index | Anomaly Type | GasASTMF2897SteelPipeMaterial | Inspection Range Type | Item Number Shortstop | Valve Material | Valve Type | DocumentType | GasASTMF2897CompositePipeMaterial | PipePressureRating | GasASTMF2897Transitions | Operating Classification | Gas Pipe Diameter Units | Leak Repair Type | Consequence Area Type | CP System Protection Type | Gas Pipe Diameter Plastic | Station Pipe Diameter | Pipe Casing Diameter | Pipe Fitting Material | Leak Inspect GasIn | AnnotationStatus | ILI Survey Marker Type | EFV Diameter | Gas Service Diameter Bare Steel | Gas Pipe Diameter Bare Steel | PipeMaterial | Gas Service Diameter Cast Iron | Pipe Casing Fill Type | Gas Service Diameter Plastic Other | Valve Position | GasASTMF2897Valve | Pipe Crossing Topographic | Structures Limited Mobility Reason | Leak Work Performed | Wellhead Diameter | Anomaly Severity | Time Classification | dLRSNetworks | GasASTMF2897Tees | ILI Survey Type | Corrosion Condition | Vault Material | Spatial Accuracy | Could Affect Type | Wellhead Connection type | ValueMethod | Fitting Style | PipeTestType | Product Commodity Type | Pipe Connection Type | UnitsForDiameter | Item Number Meter | HS LS | Line Valve Connection Type | Structure Types | GasASTMF2897IronPipeMaterial | GasASTMF2897CopperPipeMaterial | dActivityType | Strainer Device Type | DA Survey Type | Valve Diameter | Pipe Install Method | Alignment Sheet Type | Leak Cause Excavation | Pipe Outside Diameter Coated Steel | Pressure Test Type | Odorizer Size | Gas Pipe Diameter Composite | CP System Status | Pressure Monitor Device Manufacturer | CP Color Code | Strainer Manufacturer | HCA Area Type | StrainerModel | Anode Weight | Pipe Fitting Diameter | Pipe Crossing Wired Utility | DOTClassType | Pipe Outside Diameter Bare Steel | Leak Survey Method | ControlLineModel | Material4 | GasASTMF2897Strainers | Wellhead Pressure Rating | Recording Method | Anode Material Type | CP Bond Junction Type | Wellhead Type | PipeEditResponse | Gas Service Diameter Wrought Iron | Anomaly Status | Gas Service Diameter Ductile Iron | GasASTMF2897PlasticPipeMaterial | EnabledDomain | Test Point Num Wires | Pipe System Type | GasASTMF2897EndCap | VerticalAlignment | InspRemediation | Gas Service Diameter Copper | UnitsForLength | BooleanDomain | Pressure Test Medium | PipeManufacturer | DOTClassSource | Identified Site Outside Area | Pressure Established By | InspectionNote_Type | Company ID | IdentifiedIssue | PipeCondition | States | Corrosion Extent | Pipe Crossing Location | Operating Type | GasASTMF2897BSteelPipeType | ExcavDam Resp Party Type | Gas Pipe Diameter Coated Steel | ExcavDam Equip Cause Damage | Present Status | PipelineMarker | Over Pressure Protection Type | Pipe Crossing Transportation | Pipeline Operator | AncillaryRoleDomain | BooleanSymbolValue | System Numbers | Object Status | GasASTMF2897Reducers | Pipe Material | Valve Manufacturer | Leak Force NatForce.
>>>

0 Kudos
5 Replies
FC_Basson
MVP Regular Contributor

I found that the arcpy command syntax was the issue.

Replace the following arcpy commands:
arcpy.CreateDomain_management with arcpy.management.CreateDomain
arcpy.AddCodedValueToDomain_management with arcpy.management.AddCodedValueToDomain

See the syntax here: https://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/create-domain.htm

0 Kudos
Cristian_Galindo
Occasional Contributor III

It does not make sense, because the example in the same documentation states:

# 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)

are those, two different syntaxes for the same implementation? or are two different implementations?

 

0 Kudos
FC_Basson
MVP Regular Contributor

Same kind of question here: https://community.esri.com/t5/python-questions/arcpy-management-lt-gp-tool-gt-vs-arcpy-lt-gp-tool/td...  So I guess it is the same implementation, but with different syntax.  The old syntax broke my GP tool that I created in Pro, but changing it to the new syntax made it work.  

0 Kudos
Cristian_Galindo
Occasional Contributor III

I understand that now your GP tool work....How, if the the implementation and the tool are the same, the syntax breaks that, moreover, when the errors shows, that something was executed, therefore it was not something related with python syntax.

0 Kudos
FC_Basson
MVP Regular Contributor

Well, I'm also not sure why the "modern" version of the syntax resolved my issue, but that was the only way I could get the tool to work.  What I also found was the autocomplete for the commands in the Python console in Pro automatically selects the modern syntax as specified in the parameters for the tool in all the docs.  Hopefully, someone from Esri can give us more insight into the issue.