def getValues(featureClass,FieldName): desc = arcpy.Describe(featureClass) cur = arcpy.SearchCursor(featureClass) row = cur.next() names = [] while row: name = str(row.getValue(FieldName)) #would like to get description and not code value on this line... try: ind = names.index(name) except: names.append(name) row = cur.next() return(names)
Is there a built-in function that will help me in finding the domain name of a field using the field's name so that I can use the domain name in the DomainToTable function?
fieldList = arcpy.ListFields(myFC) for field in fieldList: print field.name + " - " + str(field.domain)
#workspace is a parameter taken as input on the tool (example.gdb would be the workspace, for example) #domain is a field.domain value: fields are listed using arcpy.ListFields(aFeatureClass) function, iterated through to find the correct field and then that field's domain is placed into a variable called "domain" #the last 3 inputs are made up names for the table, code and description values respectively arcpy.DomainToTable_management(workspace, domain, "ExampleTable", "code", "description")
workspace = r"C:\temp\test.gdb" myFC = workspace + "\\my_fc" domainList = [] fieldList = arcpy.ListFields(myFC) for field in fieldList: if field.domain != '' and field.domain not in domainList: domainList.append(field.domain) for domain in domainList: domainTable = workspace + "\\domain_table_for_" + domain.replace(" ", "_") #replace any blanks with an underscore arcpy.DomainToTable_management(workspace, domain, domainTable, "code", "description") #assuming cosde and description are the names
workspace = r"C:\temp\test.gdb" dsc = arcpy.Describe(workspace) for domain in dsc.domains: domainTable = workspace + "\\domain_table_for_" + domain.replace(" ", "_") #replace any blanks with an underscore arcpy.DomainToTable_management(workspace, domain, domainTable, "code", "description") #assuming cosde and description are the name
I did not think that I would need to include the workspace it had to be placed inside
arcpy.env.workspace = r"C:\temp\test.gdb"
myWorkspace = r"C:\temp\test.gdb" arcpy.env.workspace = myWorskpace dsc = arcpy.Describe(arcpy.env.workspace) for domain in dsc.domains: domainTable = "domain_table_for_" + domain.replace(" ", "_") #replace any blanks with an underscore NOTE I ONLY INCLUDE THE TABLE NAME HERE, SINCE I ALREADY SET THE WORSKPACE arcpy.DomainToTable_management(workspace, domain, domainTable, "code", "description") #assuming cosde and description are the name
arcpy.env.workspace = r"C:\temp\test.gdb" fcList = arcpy.ListFeatureClasses() for fc in fcList: print fc