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 ArcGIS Pro: 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 for users to export or save attachments 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.
Note: The workflow requires a Desktop Standard or Desktop Advanced license.
To batch export attachments from a feature class in ArcGIS Pro, create a script tool from a Python script that enables exporting attachments in batches from a feature class. Run the script tool by providing the parameters required.
Note: The script provided requires the standard attachment table, which is created when attachments are enabled as the input on a feature class. This is because it relies on the DATA, ATT_NAME and ATTACHMENTID fields stored in the table. A typical naming convention is to append _ATTACH to the end of the table name.
- Copy and paste the following script into a Notepad, and save it as ExportAttachments.py.
Note: The following script iterates through the entire attachment table of a single feature class and copies 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 filenum = "ATT" + str(item) + "_" filename = filenum + str(item) open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes()) del item del filenum del filename del attachment
- In ArcGIS Pro, right-click a toolbox in the Catalog pane, and click New > Script
- On the script tool property page, set the properties of the script tool as follows:
- 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 displays the name of the script tool, as shown in the Geoprocessing pane.
- Click 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.
- Check the Store tool with relative path check box.
- 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 and it defines the table containing the attachments to export.
- 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.
- Click OK. A new script tool is added to the toolbox.
- Double-click to open the created script tool. Set the parameters of the tool as follows to export the attachments in a batch.
- In the tool dialog box, browse for the attachments table containing the attachments to export in the Attachments Table parameter.
- In the Output Location parameter, select a folder to save the exported attachments, and click OK.
- Click Run.
- How To: Batch export attachments from a feature class
- ArcGIS Pro: Create a script tool
- ArcGIS Pro: Adding a script tool
- ArcGIS Pro: Setting script tool parameters
- ArcGIS Pro: ArcGIS Desktop licensing
Last Published: 1/9/2020
Article ID: 000017450
Software: ArcGIS Pro 2.4.2, 2.4.1, 2.4, 2.3.3, 2.3.2, 2.3.1, 2.3, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2