Hello! (& Thank you!) Using ArcGIS Pro 2.8.3
I am wrapping up a survey conducted in survey123, where data was hosted in AGOL. It cannot stay there, and must be downloaded. I have run a test and downloaded the data into a gdb, and I have run the script to batch export the photos ( How To: Batch export attachments from a feature class in ArcMap (esri.com) )
The issue: the naming of the photo files is long and not user-friendly. Each photo is from the related table of a survey that is surveying houses/properties. The related table has a 'Full_Address' or 'PIN' (parcel ID) field which would be great for the file name.
How would I modify the script to put the PIN or Address from the related table instead of say the ATTACHMENTID ? or ATT_NAME?
Script from link above:
import arcpy
from arcpy import da
import os
inTable = arcpy.GetParameterAsText(0)
fileLocation = arcpy.GetParameterAsText(1)
with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID']) as cursor:
for item in cursor:
attachment = item[0]
filenum = "ATT" + str(item[2]) + "_"
filename = filenum + str(item[1])
open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())
del item
del filenum
del filename
del attachmentI have found another resource (below), but my python skills are quite limited at this point and I cannot follow how I would need to adjust what they provide for me to get what I need.
arcpy - Renaming photo attachments? - Geographic Information Systems Stack Exchange
Thank you again for taking the time to assist!
You could do something like this:
originTable = <path>
targetTable = <path>
originData = [row for row in arcpy.da.SearchCursor(originTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID']]
targetData = [row for row in arcpy.da.SearchCursor(targetTable, ['Full_Address', 'PIN']]
for origin_row, target_row in zip(originData, targetData):
# now do what you did but use target_row[0] or target_row[1] for
# constructing your filename.