Hey all,
I'm using field values as input for naming exported attachments, and I'm running into an issue with domains.
Namely, if the field uses a coded value domain, it will grab the code and not the value.
How can I grab the value?
I found this post here but I'm not sure how to put it together; I was able to create the initial dictionary of codes and values, but I'm not sure how to connect that to my fields afterwards.
The code runs as :
- Look up the RELKEY from the Attachment Table in the Feature Class
- Grab the Name from the Feature Class (End here if no domain or if the domain is a range.)
- Use the Name from the Feature Class to Lookup the Coded value in the Domain Table
- Grab the Value for the Code from the Domain Table

I have steps 1,2, and 4, but I can't figure out how to make step 3 work.
Code sample
'''Rough order of how I think it should go?
Step 1 is definitely supposed to be at the bottom'''
'''Step 4''' # Mostly lifted directly from that example I link
testDom = arcpy.ListFields(inFC)
for field in testDom:
if field.domain != "": #I only care about domains if there is one. Also need to specify that it's a coded value domain somehow.
cvdTable = arcpy.DomainToTable_management(myGDB, field.domain, 'in_memory/cvdTable', 'codeField', 'descriptionField')
d = {} #Create an empty dictionary.
rows = arcpy.SearchCursor(cvdTable) #Create a cursor to loop through the table holding the domain and code info
for row in rows: # Loop through each row in the table.
d[row.codeField] = row.descriptionField # For each row in the table populate the key with the code field and the value from the description field
'''Step 2'''
primeNames = dict()
with arcpy.da.SearchCursor(FeatureClass, [relPairO, nameField1]) as cursor:
for row in cursor:
primeNames[row[0]] = row[1] #Every time you check this dictionary for the relation key, it will direct you to the right entry in the primary naming field.
'''Step 1'''
with arcpy.da.SearchCursor(inTable,['DATA', 'ATT_NAME', 'ATTACHMENTID', relPairA]) as cursor:
for row in cursor:
relPairKey = row[3]
fieldValue = primeNames[relPairKey] # Value of specified field in feature class
Also, this is a total beginner question, but in the example that I linked, what happens to that domain table? Is it automatically deleted?
Thanks!