Select to view content in your preferred language

Export Attachments - Without a Feature Layer and Multiple _ATTACH Tables in Geodatabase

169
2
05-02-2025 12:16 PM
GarrettRSmith
Frequent Contributor

Hello Everyone

We have created a survey that is being used to collect photographs at different points throughout our study area. We have a geopoint question, but that is only used for navigational purposes. 

We had a test round of data collection a couple of weeks ago and are now downloading the data. The issue that we are running into is that each photo site has its own repeat, so we have 25 _ATTACH tables in our .gdb. 

Survey123_02.png

I have created a script based on the Python code referenced in this demonstration below:

https://support.esri.com/en-us/knowledge-base/how-to-batch-export-attachments-from-a-feature-class-i...

But, the issue that I am running into is that I am only allowed to enter one _ATTACH table at a time. Is there a way I can do a batch export based on there being multiple _ATTACH tables in the .gdb? Otherwise, I suppose my easier, but time consuming option, would be to just run the Export Attachments tool.

Thanks all.

0 Kudos
2 Replies
Neal-Kittelson
Frequent Contributor

You could make an array of your table names, and do a for loop for each of the tables in the array.

PhotoTbls = [ "PhotositeUP02_Attach", ""PhotositeUP03_Attach",....]

for PT in PhotoTbls:

      <your script here>

 

0 Kudos
RyanUthoff
MVP Regular Contributor

There might be more elegant ways of doing it, but you could just modify the script you linked to export all 25 attachment tables at once. Just copy and paste lines 5-17 over and over again, and just modify your inTable and fileLocation variables. Notice how I changed inTable1 = arcpy.GetParameterAsText(0) in line 5 to inTable2 = arcpy.GetParameterAsText(3) in line 19. You'll also need to change the corresponding variables that are referenced in the code as well.

And then when you create your tool, you'll just create 25 user inputs. If your output location is going to be the same for every attachment table, you would just create that variable once and wouldn't have to create a copy of it for each attachment table.

import arcpy
from arcpy import da
import os

inTable1 = arcpy.GetParameterAsText(0)
fileLocation1 = arcpy.GetParameterAsText(1)

with da.SearchCursor(inTable1, ['DATA', 'ATT_NAME', 'ATTACHMENTID']) as cursor:
    for item in cursor:
        attachment = item[0]
        filenum = "ATT" + str(item[2]) + "_"
        filename = filenum + str(item[1])
        open(fileLocation1 + os.sep + filename, 'wb').write(attachment.tobytes())
        del item
        del filenum
        del filename
        del attachment

inTable2 = arcpy.GetParameterAsText(2)
fileLocation2 = arcpy.GetParameterAsText(3)

with da.SearchCursor(inTable2, ['DATA', 'ATT_NAME', 'ATTACHMENTID']) as cursor:
    for item in cursor:
        attachment = item[0]
        filenum = "ATT" + str(item[2]) + "_"
        filename = filenum + str(item[1])
        open(fileLocation2 + os.sep + filename, 'wb').write(attachment.tobytes())
        del item
        del filenum
        del filename
        del attachment

 

0 Kudos