Enable Attachments (Data Management)

License Level:BasicStandardAdvanced

Summary

Enables attachments on a geodatabase feature class or table. Creates the necessary attachment relationship class and attachment table that will internally store attachment files.

Usage

Syntax

EnableAttachments_management (in_dataset)
ParameterExplanationData Type
in_dataset

Geodatabase table or feature class for which attachments will be enabled. The input must be in a version 10 or later geodatabase.

Table View

Code Sample

EnableAttachments example (Python window)

The following code snippet illustrates how to use the EnableAttachments tool in the Python window.

import arcpy
arcpy.EnableAttachments_management(r"C:\Data\City.gdb\Parcels")
EnableAttachments example (stand-alone Python script)

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

"""
Example: we have a folder of digital photographs of vacant homes; the photos
are named according to the ParcelID of the house in the picture. Let's add
these photos to a parcel feature class as attachments.
"""

import csv
import arcpy
import os
import sys

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

try:
    # create a new Match Table csv file
    writer = csv.writer(open(matchTable, "wb"), delimiter=",")

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

    # iterate through each picture in the directory and write a row to the table
    for file in os.listdir(picFolder):
        if str(file).find(".jpg") > -1:
            writer.writerow([str(file).replace(".jpg", ""), file])

    del writer

    # the input feature class must first be GDB attachments enabled
    arcpy.EnableAttachments_management(input)

    # use the match table with the Add Attachments tool
    arcpy.AddAttachments_management(input, targetField, matchTable, matchField, pathField, picFolder)
except:
    print arcpy.GetMessages(2)

Environments

Related Topics

Licensing Information

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