How To: Batch export attachments from a feature class in ArcGIS Pro


ArcGIS Pro provides the capability to export attachments from a feature class by saving the attached file to a file system, as described in the following document: Save an attached file. However, this capability is limited to saving the attachments of only one feature at a time. There is no geoprocessing tool that allows users to export or save all attachments that are attached to all features in one process.

The instructions provided describe a method to batch export attachments from a feature class by creating a script tool to accomplish the task.


To batch export attachments from a feature class in ArcGIS Pro, create a script tool from a Python script that allows exporting attachments in a batch from a feature class, using the workflow provided below, and run the created script tool by providing the parameters that are required by the tool.

The script used to export the attachments requires the input table to be the standard attachment table created when attachments are enabled on a feature class. This is because the script relies on the DATA, ATT_NAME and ATTACHMENTID fields stored in this table. The typical naming convention of the attachment table must append _ATTACH to the end of the table name.
  1. Copy and paste the following script into Notepad, and save it as ExportAttachments.py.
The following script iterates through the entire attachment table of a single feature class and copies all the attachments (saved as BLOBs or binary large objects) to a file.
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 attachment
  1. In ArcGIS Pro, right-click a toolbox in the Catalog pane, and click New > Script
    An image of the steps to create a new script tool in a toolbox.
  2. In the script tool property page, set the properties of the script tool as below.
    1. In the General section, type the Name and Label for the script tool. For example, type ExportAttachments as the Name, and Export Attachments as the Label. The label is the display name for the script tool, as shown in the Geoprocessing pane.
    2. Click the Browse icon An image of the Browse icon. next to the Script File field, and navigate to the location of the script file saved in Step 1, select the script, and click OK.
    3. Check the Store tool with relative path check box.
      An image of the General section of the script tool property page.
    4. In the Parameters section, type Attachments Table in the first row of the Label column, and set the Data Type as Table. This is the first parameter of the script tool. This parameter defines the table containing the attachments to export.
    5. In the second row, add a second parameter with the Label name as Output Location, and set the Data Type as Folder. This parameter defines the folder to locate the exported attachments.  
      An image of the Parameters section of the script tool property page.
    6. Click OK. A new script tool is added to the toolbox.
      An image of the created Export Attachments script tool.
  3. Double-click the created script tool to open the tool. Set the parameters of the tool as below to export attachments in batch.
    1. In the tool dialog, browse for the attachments table containing the attachments to be exported in the Attachments Table parameter.
    2. In the Output Location parameter, select a folder to save the exported attachments, and click OK.
    3. Click Run.  
      An image of the Export Attachments tool dialog box.
      The attachments are successfully exported in batch, and located in the folder defined in the Output Location parameter.
      An image of the list of the exported attachments.

Related Information