Select to view content in your preferred language

Is it possible to use a field for the filename of an attachment export?

2215
10
Jump to solution
06-14-2018 01:46 PM
CraigSchellenbach1
New Contributor III

Hello,

I am able to export photo attachments with the generic script but I would like to name them based on a field on the record they are attached to. The field I would like to use is 'FID' and it's unique to each row in the table. The current code I use is. 

import arcpy
from arcpy import da
import os

inTable = arcpy.GetParameterAsText(0)
fileLocation = arcpy.GetParameterAsText(1)

with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'Access Point FQN_ID']) 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 attachment

0 Kudos
10 Replies
RandyBurton
MVP Alum

I would use ArcCatalog to verify that the path and name of the attachment table is correct.  My initial guess is that the attachment table's name is actually '...\Observations__ATTACH' (with 2 underscore characters).  It appears that you are using only one underscore between Observations and ATTACH.

0 Kudos