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: We have a folder of .jpg photographs and .pdf files;
We want to add these files as attachments to our input dataset.
Create a match table, enable input dataset if needed, add attachments.
"""
import arcpy

input_dataset = r"C:\Data\City.gdb\Parcels"
input_path = arcpy.Describe(input_dataset).path

# GenerateAttachmentsMatchtable parameters
# Required
match_table = r"C:\Data\City.gdb\parcelsMatchtable"
key_field = 'PARCELS'
# Optional
data_filter ='*.jpg; *.pdf'  # Remove *.pdf to load only the .jpg images as another option.
rel_path = "RELATIVE"
match_pattern = 'ANY'
# pic_folder required for match table, optional for add attachments if rel_path is ABSOLUTE
pic_folder = r"C:\Pictures\Parcels"

arcpy.management.GenerateAttachmentMatchTable(input_dataset, pic_folder, match_table, key_field,
                                              data_filter, rel_path, match_pattern)

# Check if input dataset is enabled for attachments
rel_class = arcpy.Describe(input_dataset).relationshipClassNames
rel_class_path = (f"{input_path}\\{relclass[0]}")
rel_class_att = arcpy.Describe(relclassPath).isAttachmentRelationship

if rel_class_att:
    pass
else:
    arcpy.management.EnableAttachments(input_dataset)

# AddAttachments parameters
add_match_table = match_table
input_join_fld = 'ObjectID'
match_join_fld = 'MatchID'
match_path_fld = 'Filename'

# Add attachments from generated match table to input data ATTACH table
arcpy.management.AddAttachments(input_dataset, input_join_fld, add_match_table,
                                match_join_fld, match_path_fld, pic_folder)

Environments

Related topics