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, but rather 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.

Illustration

Remove Attachments 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, which stores attachments and maintains linkage to the Input Dataset.

Parameters

LabelExplanationData Type
Input Dataset

Geodatabase table or feature class from which to remove attachments. Attachments are not removed directly from this table, but rather from the related attachment table that stores the attachments. The Input Dataset must be in a version 10 or later geodatabase, and the table must have attachments enabled.

Table View
Input Join Field

Field from the Input Dataset that has values which match the values in the Match Join Field. Records that have join field values that match between the Input Dataset and the Match Table will have attachments removed. This field can be an Object ID field or any other identifying attribute.

Field
Match Table

Table that identifies which input records will have attachments removed.

Table View
Match Join Field

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

Field
Match Name Field
(Optional)

Field from the match table that has the names of attachments to remove from Input Dataset records. If no name field is specified, all attachments will be removed from each record specified in the Match Join Field. 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 attachment 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

Geodatabase table or feature class from which to remove attachments. Attachments are not removed directly from this table, but rather from the related attachment table that stores the attachments. The Input Dataset must be in a version 10 or later geodatabase, and the table must have attachments enabled.

Table View
in_join_field

Field from the Input Dataset that has values which match the values in the Match Join Field. Records that have join field values that match between the Input Dataset and the Match Table will have attachments removed. This field can be an Object ID field or any other identifying attribute.

Field
in_match_table

Table that identifies which input records will have attachments removed.

Table View
in_match_join_field

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

Field
in_match_name_field
(Optional)

Field from the match table that has the names of attachments to remove from Input Dataset records. If no name field is specified, all attachments will be removed from each record specified in the Match Join Field. 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 attachment 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 tool in the Python window.

import arcpy
arcpy.RemoveAttachments_management(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 tool 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