Add Attachments (Data Management)

Summary

Adds file attachments to the records of a geodatabase feature class or table. The attachments are stored in the geodatabase in a separate attachment table that maintains linkage to the target dataset. Attachments are added to the target dataset using a match table that indicates for each input record (or an attribute group of records) the path to a file to add as an attachment to that record.

Learn more about working with the tools in the Attachments toolset

Illustration

Add Attachments tool illustration

Usage

  • This tool does not honor selections.

  • Before attachments can be added using this tool, they must be enabled using the Enable Attachments tool.

  • Attachments that are added using this tool will be copied to the geodatabase. The original attachment files will not be affected. If the original files are modified, the changes will not be automatically made to the geodatabase attachment. To synchronize changes to the geodatabase, remove the affected attachments using the Remove Attachments tool. Then add the modified files back as new attachments.

  • If the Input Dataset parameter value contains an existing field that is the path to the attachments to add, and you do not want to use a separate value for the Match Table parameter, specify the same dataset for both the Input Dataset and Match Table parameters. The tool will automatically select the Object ID field for both join fields, and you can specify which field from the input contains the paths to the attachment files.

  • Multiple files can be attached to a single feature class or table record. To accomplish this, ensure that the Match Table parameter value contains multiple records for that input ID. For example, record 1 has an input ID of 1 and a path name of pic1a.jpg, and record 2 has an input ID of 1 and a path name of pic1b.jpg.

Parameters

LabelExplanationData Type
Input Dataset

The geodatabase table or feature class where attachments will be added. Attachments are not added directly to this table, but to a related attachment table that maintains linkage to the input dataset.

The dataset must be stored in a version 10.0 or later geodatabase, and the table must have attachments enabled.

Table View
Input Join Field

A field from the Input Dataset parameter value that has matching values in the Match Join Field parameter value. Records with matching values will have attachments added. This field can be an Object ID field or any other identifying attribute.

Field
Match Table

A table that identifies which input records will have attachments added and the paths to those attachments.

Table View
Match Join Field

A field from the Match Table parameter value that indicates which records in the Input Dataset parameter value will have specified attachments added.

Field
Match Path Field

A field from the Match Table parameter value that contains paths to the attachments to add to the records of the Input Dataset parameter value.

A field from the in_match_table parameter value that contains paths to the attachments to add to the records of the in_dataset parameter value.

Field
Working Folder
(Optional)

A folder or workspace where attachment files are centralized. By specifying a working folder, the paths in the Match Path Field parameter value can be the short names of files relative to the working folder.

For example, if loading attachments with paths such as C:\MyPictures\image1.jpg and C:\MyPictures\image2.jpg, use a parameter value of C:\MyPictures. Then the paths in the Match Path Field parameter value can be the short names such as image1.jpg and image2.jpg instead of the full paths.

Folder

Derived Output

LabelExplanationData Type
Updated Input Dataset

The updated input dataset.

Table View

arcpy.management.AddAttachments(in_dataset, in_join_field, in_match_table, in_match_join_field, in_match_path_field, {in_working_folder})
NameExplanationData Type
in_dataset

The geodatabase table or feature class where attachments will be added. Attachments are not added directly to this table, but to a related attachment table that maintains linkage to the input dataset.

The dataset must be stored in a version 10.0 or later geodatabase, and the table must have attachments enabled.

Table View
in_join_field

A field from the in_dataset parameter value that has matching values in the in_match_join_field parameter value. Records with matching values will have attachments added. This field can be an Object ID field or any other identifying attribute.

Field
in_match_table

A table that identifies which input records will have attachments added and the paths to those attachments.

Table View
in_match_join_field

A field from the in_match_table parameter value that indicates which records in the in_dataset parameter value will have specified attachments added.

Field
in_match_path_field

A field from the Match Table parameter value that contains paths to the attachments to add to the records of the Input Dataset parameter value.

A field from the in_match_table parameter value that contains paths to the attachments to add to the records of the in_dataset parameter value.

Field
in_working_folder
(Optional)

A folder or workspace where attachment files are centralized. By specifying a working folder, the paths in the in_match_path_field parameter value can be the short names of files relative to the working folder.

For example, if loading attachments with paths such as C:\MyPictures\image1.jpg and C:\MyPictures\image2.jpg, use a parameter value of C:\MyPictures. Then the paths in the in_match_path_field parameter value can be the short names such as image1.jpg and image2.jpg, instead of the full paths.

Folder

Derived Output

NameExplanationData Type
out_dataset

The updated input dataset.

Table View

Code sample

AddAttachments example 1 (Python window)

The following code snippet demonstrates how to use the AddAttachments function in the Python window.

import arcpy
arcpy.management.AddAttachments(
    r"C:\Data\City.gdb\Parcels", "ParcelID", r"C:\Data\matchtable.csv", 
    "ParcelID", "Picture", r"C:\Pictures")
AddAttachments example 2 (stand-alone script)

The following script demonstrates how to use the AddAttachments function in a stand-alone script.

"""
Example: You have a folder of digital photographs of vacant homes; the photos
are named according to the Parcel ID of the house in the picture. Add
these photos to a parcel feature class as attachments.
"""

import arcpy
import os

input = r"C:\Data\City.gdb\Parcels"
inputField = "ParcelID"
matchTable = r"C:\Data\matchtable.csv"
matchField = "ParcelID"
pathField = "Picture" 
picFolder = r"C:\Pictures"

# Create a Match Table csv file
with open(matchTable, "w") as csv:
    # write a header row (the table will have two columns: ParcelID and Picture)
    csv.write(f"{matchField},{pathField}\n")
    
    # Iterate through each picture in the directory and write a row to the table
    for file in os.listdir(picFolder):
        if file.find(".jpg") > -1:
            csv.write(f"{file.replace('.jpg', '')},{file}\n")

# The input feature class must first have GDB attachments enabled
arcpy.management.EnableAttachments(input)

# Use the match table with the Add Attachments tool
arcpy.management.AddAttachments(input, inputField, matchTable, matchField, 
                                pathField, picFolder)

Environments

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics