I have a geodatabase that has multiple domains (50 +) and I want to assign them to specific feature class fields (there's over 50 feature classes) in an automated way because I'd like to run this script on a nightly basis.
For example, I have a feature class named "Hydrant" and two domains (Hyd_MAKE, Hyd_SIZE) that I want to assign to the "Hydrant" feature class fields "Make" and "Size" respectively. In addition to the "Hydrant" feature class, I have several other feature class fields (around 50 feature classes) that I want to assign other domains to. Is there a Python script that I can write to accomplish this or should I go with another route?
I know I can use AssignDomainToField to assign domains to a feature class field but I want to automate this with a For Loop or some other iterative process; That hasn't been working out too well.
Here is what I have so far (I am open to a completely different direction; this is just what I originally thought of):
import arcpy aWS = r"GDBPath" arcpy.env.workspace = aWS arcpy.env.overwriteOutput = True # Assign domain to field fcList = arcpy.ListFeatureClasses() for fc in fcList: print fc fields = arcpy.ListFields(fc) for field in fields: print "Field: " + field.name # Hydrant feature if fc == "Hydrant": fh = fc # name of fields f_fh_list = ["Make", "Size"] f_fh_list.sort() for f_fh in f_fh_list: print f_fh domains = arcpy.da.ListDomains() ##Loop through all domains for domain in domains: fh_dn = domain.name fh_dom_list = ["Hyd_MAKE","Hyd_SIZE"] fh_dom_list.sort() if fh_dn in fh_dom_list: arcpy.AssignDomainToField_management(fh, f_fh, fh_dn) else: print "Next domain" else: print "Next feature