I am creating a point feature class in a file geodatabase to use a template so users can create standardized data. I have successfully created subtypes and domains for the database with a Python script. All of that works as expected but now I need to assign the domain to an attribute and set a default value to a different field. This is where it gets cloudy.

The problem is a mismatch between the subtype/domain and the country. For example, the subtype for “Country A” should have the domain for “Country A” assigned to a field and another value assigned to a different field. What’s happening is the first country’s Subtype/Domain/Attribute settings are blank, the second country gets the values that should be assigned to the first country, and the third country gets the values for the second country and so on through the database.

We are running ArcGIS 10.6, ArcGIS Pro 2.3 and IDLE (ArcGIS Pro). I cannot use earlier or later versions of ArcGIS/ArcPro and altering an existing database is not an option.

import arcpy, time

print("STARTING TIME: ", time.asctime())

    arcpy.env.workspace =  "TestFinal/Events.gdb"
    # Set local parameters
    inFeatures = "DRAFT/TemplateTest_1"
    inField_1 = "Sub"
    inField_2 = "Org"
    group_1 = ["Algeria","Angola","Benin"]  
    group_2 = ["Kazakhstan","Kuwait","Kyrgyzstan"]
    group_3 = ["Thailand","Albania", "Cambodia", "Åland"]
    stypeDict = {"1": "Algeria","2": "Angola","3": "Åland", \
                "4": "Benin", "5": "Kazakhstan", "6": "Kuwait",\
                "7": "Kyrgyzstan", "8": "Thailand", "8": \
                "Albania", "10": "Cambodia"} 
    arcpy.SetSubtypeField_management(inFeatures, "", "True")
    arcpy.SetSubtypeField_management(inFeatures, "Location")
    arcpy.AddSubtype_management(inFeatures, "0", "Unknown")
    arcpy.AssignDomainToField_management(inFeatures, inField_1, "Unknown")
    for code in stypeDict:
        arcpy.AddSubtype_management(inFeatures, code, stypeDict[code])
        arcpy.AssignDomainToField_management(inFeatures, inField_1, stypeDict[code])
        if stypeDict[code] in group_1:
            defval = 'Blue'
        elif stypeDict[code] in group_2:
            defval = 'Green'
        elif stypeDict[code] in group_3:
            defval = 'Red'
        arcpy.AssignDefaultToField_management (inFeatures, inField_2, defval)
    # Process: Set Default Subtype...
    arcpy.SetDefaultSubtype_management(inFeatures, "0")

except Exception as err:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.