<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: arcpy.AssignDefaultToField_management not assiging a default to a field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-assigndefaulttofield-management-not-assiging/m-p/1283868#M67542</link>
    <description>&lt;P&gt;I believe that the defaults are not applied to existing records in your feature class, but the are applied only to new records being added.&amp;nbsp; To update existing records you could run&amp;nbsp;arcpy.management.CalculateField&lt;/P&gt;</description>
    <pubDate>Fri, 28 Apr 2023 14:19:05 GMT</pubDate>
    <dc:creator>DonMorrison1</dc:creator>
    <dc:date>2023-04-28T14:19:05Z</dc:date>
    <item>
      <title>arcpy.AssignDefaultToField_management not assiging a default to a field</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-assigndefaulttofield-management-not-assiging/m-p/1283861#M67541</link>
      <description>&lt;P&gt;When originally setting this up I solved this problem ... somehow, now I can't recall how for the life of me.&lt;/P&gt;&lt;P&gt;After adding some fields to a file geodatabase feature class (TWP+"_RIGHTS"), I create and apply domains to three of the fields. The default is supposed to be "Choose", yet it just shows "&amp;lt;Null&amp;gt;". Any ideas how the problem can be corrected?&lt;/P&gt;&lt;LI-CODE lang="python"&gt; # create and set domains to fields

arcpy.env.workspace = projectfilepath + county+"_"+TWPfileGDB 
RIGHTS = TWP + "_RIGHTS"
# Set local parameters
gdb = projectfilepath + county+"_"+TWPfileGDB
inFeatures = RIGHTS
default_value = 0

domName = "OpCo_Domain"
domain_description = "OpCo Choices"
inField = "OpCo"
# Process: Create the coded value domain

existingDomains = arcpy.da.ListDomains(gdb)
domain_names = [i.name for i in existingDomains]

if domName in domain_names:
    print(domName + " already exists")
    arcpy.management.AssignDomainToField(inFeatures, inField, domName)
    arcpy.AssignDefaultToField_management(inFeatures, inField, default_value)
    
else:
    print("creating domain " + domName)
    arcpy.management.CreateDomain(gdb, domName, domain_description, "TEXT", "CODED")
    domDict = {"0": "Choose", "1": "METC", "2": "ITCT"}
    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)
    arcpy.AssignDefaultToField_management(inFeatures, inField, default_value)
    


domName_2 = "RightsType_Domain"
domain_description_2 = "RightsType Choices"
inField_2 = "RightsType"

existingDomains = arcpy.da.ListDomains(gdb)
domain_names = [i.name for i in existingDomains]

if domName_2 in domain_names:
    print(domName_2 + " already exists")
    arcpy.management.AssignDomainToField(inFeatures, inField_2, domName_2)
    arcpy.AssignDefaultToField_management(inFeatures, inField_2, default_value)
    
else:
    print("creating domain " + domName_2)
    arcpy.management.CreateDomain(gdb, domName_2, domain_description_2, "TEXT", "CODED")
    domDic_2 = {"0": "Choose", "1": "Easement", "2": "Fee", "3": "License"}
    for code in domDic_2:        
        arcpy.management.AddCodedValueToDomain(gdb, domName_2, code, domDic_2[code])
    # Process: Constrain the material value of distribution mains
    arcpy.management.AssignDomainToField(inFeatures, inField_2, domName_2)
    arcpy.AssignDefaultToField_management(inFeatures, inField_2, default_value)
        
        
        
domName_3 = "Type_of_Use_Domain"
domain_description_3 = "Type_of_Use Choices"
inField_3 = "Type_of_Use"

existingDomains = arcpy.da.ListDomains(gdb)
domain_names = [i.name for i in existingDomains]

if domName_3 in domain_names:
    print(domName_3 + " already exists")
    arcpy.management.AssignDomainToField(inFeatures, inField_3, domName_3)
    arcpy.AssignDefaultToField_management(inFeatures, inField_3, default_value)

else:
    print("creating domain " + domName_3)
    arcpy.management.CreateDomain(gdb, domName_3, domain_description_3, "TEXT", "CODED")
    domDict_3 = {"0": "Choose", "1": "Full T-Line", "2": "Substation", "3": "Railroad", "4": "Overhang Only", 
                "5": "Veg Management Only", "6": "Access", "7": "Other"}
    for code in domDict_3:        
        arcpy.management.AddCodedValueToDomain(gdb, domName_3, code, domDict_3[code])
    # Process: Constrain the material value of distribution mains
    arcpy.management.AssignDomainToField(inFeatures, inField_3, domName_3)
    arcpy.AssignDefaultToField_management(inFeatures, inField_3, default_value)


print("Completed"+" "+time.strftime("%x" +" "+ "(%a)" +" "+ "at"+" "+"%I:%M"))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 14:10:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-assigndefaulttofield-management-not-assiging/m-p/1283861#M67541</guid>
      <dc:creator>nsidaniel</dc:creator>
      <dc:date>2023-04-28T14:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.AssignDefaultToField_management not assiging a default to a field</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-assigndefaulttofield-management-not-assiging/m-p/1283868#M67542</link>
      <description>&lt;P&gt;I believe that the defaults are not applied to existing records in your feature class, but the are applied only to new records being added.&amp;nbsp; To update existing records you could run&amp;nbsp;arcpy.management.CalculateField&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 14:19:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-assigndefaulttofield-management-not-assiging/m-p/1283868#M67542</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2023-04-28T14:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.AssignDefaultToField_management not assiging a default to a field</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-assigndefaulttofield-management-not-assiging/m-p/1283900#M67543</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/192850"&gt;@DonMorrison1&lt;/a&gt;&amp;nbsp; I'm not sure what you mean! I'm getting an error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;field = "Type_of_Use"
expression = "!Type_of_Use!.replace(' ', 'Choose')"
arcpy.management.CalculateField(RIGHTS, field, expression, "", "", "", "ENFORCE_DOMAINS")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the error:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Traceback (most recent call last):
  File "&amp;lt;expression&amp;gt;", line 1, in &amp;lt;module&amp;gt;
AttributeError: 'NoneType' object has no attribute 'replace'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 14:53:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-assigndefaulttofield-management-not-assiging/m-p/1283900#M67543</guid>
      <dc:creator>nsidaniel</dc:creator>
      <dc:date>2023-04-28T14:53:58Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.AssignDefaultToField_management not assiging a default to a field</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-assigndefaulttofield-management-not-assiging/m-p/1283913#M67544</link>
      <description>&lt;P&gt;Ah, I corrected my code to reference each domains' dictionary ! Thank you &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/192850"&gt;@DonMorrison1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;field = "OpCo"
expression = 0
arcpy.management.CalculateField(RIGHTS, field, expression, "", "", "", "ENFORCE_DOMAINS")

field = "RightsType"
expression = 0
arcpy.management.CalculateField(RIGHTS, field, expression, "", "", "", "ENFORCE_DOMAINS")

field = "Type_of_Use"
expression = 0
arcpy.management.CalculateField(RIGHTS, field, expression, "", "", "", "ENFORCE_DOMAINS")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 15:04:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-assigndefaulttofield-management-not-assiging/m-p/1283913#M67544</guid>
      <dc:creator>nsidaniel</dc:creator>
      <dc:date>2023-04-28T15:04:16Z</dc:date>
    </item>
  </channel>
</rss>

