Remove Attachments (Data Management)

License Level:BasicStandardAdvanced

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

Syntax

RemoveAttachments_management (in_dataset, in_join_field, in_match_table, in_match_join_field, {in_match_name_field})
ParameterExplanationData 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

Code Sample

RemoveAttachments example (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 (stand-alone Python script)

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

## Some of the attachments we added to a feature class are unnecessary, let's remove them.

import csv, arcpy, os, sys

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

Related Topics

Licensing Information

ArcGIS for Desktop Basic: No
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
5/7/2015