Remove Attachments (Data Management)

Summary

Removes attachments from geodatabase feature class or table records.

Since attachments are not actually stored in the input dataset, no changes will be made to that feature class or table. Changes will be made to the related geodatabase table that stores the attachments and maintains linkage with the input dataset. A match table is used to identify which input records (or attribute groups of records) will have attachments removed.

Learn more about working with the Attachments geoprocessing tools

Illustration

Remove Attachments tool illustration

Usage

  • An alternative to using this tool is to delete selected records from the InputDataset__ATTACH table in the same geodatabase as the Input Dataset value, which stores attachments and maintains linkage to the Input Dataset value.

  • This tool supports an ArcGIS Enterprise hosted feature layer as input.

Parameters

LabelExplanationData Type
Input Dataset

A geodatabase table or feature class from which attachments will be removed. Attachments are not removed directly from this table; they are removed from the related attachment table that stores the attachments. The dataset must have attachments enabled.

Table View
Input Join Field

A field from the Input Dataset parameter value that contains values that match the values in the Match Join Field parameter value. Records that have join field values that match the Input Dataset parameter value and the Match Table parameter value will have attachments removed. 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 removed.

Table View
Match Join Field

A field from the match table that indicates which records in the Input Dataset parameter value will have specified attachments removed. This field can have values that match the Input Dataset Object ID field or some other identifying attribute.

Field
Match Name Field
(Optional)

A field from the match table that has the names of the attachments that will be removed from the Input Dataset parameter value's records. If no name field is specified, all attachments will be removed from each record specified in the Match Join Field parameter value. If a name field is specified but a record has a null or empty value in the name field, all attachments will be removed from that record. This field's values should be the short names of the attachments to remove, not the full paths to the files used to make the original attachments.

Field

Derived Output

LabelExplanationData Type
Updated Input Dataset

The updated input dataset.

Table View

arcpy.management.RemoveAttachments(in_dataset, in_join_field, in_match_table, in_match_join_field, {in_match_name_field})
NameExplanationData Type
in_dataset

A geodatabase table or feature class from which attachments will be removed. Attachments are not removed directly from this table; they are removed from the related attachment table that stores the attachments. The dataset must have attachments enabled.

Table View
in_join_field

A field from the in_dataset parameter value that contains values that match the values in the in_match_join_field parameter value. Records that have join field values that match the in_dataset parameter value and the in_match_table parameter value will have attachments removed. 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 removed.

Table View
in_match_join_field

A field from the match table that indicates which records in the in_dataset parameter value will have specified attachments removed. This field can have values that match the in_dataset Object ID field or some other identifying attribute.

Field
in_match_name_field
(Optional)

A field from the match table that has the names of the attachments that will be removed from the in_dataset parameter value's records. If no name field is specified, all attachments will be removed from each record specified in the in_match_join_field parameter value. If a name field is specified but a record has a null or empty value in the name field, all attachments will be removed from that record. This field's values should be the short names of the attachments to remove, not the full paths to the files used to make the original attachments.

Field

Derived Output

NameExplanationData Type
out_dataset

The updated input dataset.

Table View

Code sample

RemoveAttachments example 1 (Python window)

The following code snippet illustrates how to use the RemoveAttachments function in the Python window.

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

The following script illustrates how to use the RemoveAttachments function in a stand-alone script.

# Delete unnecessary attachments from a feature class

import arcpy
import csv

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

# Create a new Match Table csv file that will tell the RemoveAttachments tool 
# which attachments to delete.
writer = csv.writer(open(matchTable, "wb"), delimiter=",")

# Write a header row (the table will have two columns: ParcelID and Picture)
writer.writerow([matchField, nameField])

# Create a list of the attachments to delete.
# Removes attachments pic1a.jpg and pic1b.jpg from feature 1, pic3.jpg from 
# feature 3, and pic4.jpg from feature 4.
deleteList = [[1, "pic1a.jpg"], [1, "pic1b.jpg"], [3, "pic3.jpg"], [4, "pic4.jpg"]]

# Iterate through the delete list and write it to the Match Table csv.
for row in deleteList:
    writer.writerow(row)

del writer

# Use the match table with the Remove Attachments tool.
arcpy.RemoveAttachments_management(input, inputField, matchTable, matchField, 
                                   nameField)

Environments

Licensing information

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

Related topics