Generate Attachment Match Table (Data Management)

Usage

  • This tool will evaluate each row in the input target dataset and compare the Key Field parameter values to the names of supported media files in the Input Folder parameter value. For each match that occurs, a record will be created in the output table that contains the Object ID value from the input dataset and the name of the matched files (or optionally the full path to the files). When used with the Add Attachments and Remove Attachments tools, the MATCHID field is used as the key field to link one or more files on disk to records in the input dataset.

  • If the Output Match Table parameter value is a folder, the output can be created as a dBASE table by specifying a name with the .dbf extension. If the output location is a geodatabase, the match table will be a geodatabase table (do not specify an extension).

Parameters

LabelExplanationData Type
Input Dataset

A dataset containing records that will have files attached.

Table View
Input Folder

A folder containing files to attach.

Folder
Output Match Table

The output match table with the MATCHID and FILENAME fields.

Table
Key Field

The field from which values will be used to match the names of the files from the input folder. The matching behavior will compare field values with each file name, disregarding the file extension. This allows multiple files with various file extensions to match a single record in the input dataset.

For example, a field value of lot5986 will match a file named lot5986.jpg if the Match Pattern parameter value is Exact.

Field
Input Data Filter
(Optional)

A data filter that will be used to limit the files considered for matching.

Wild cards (*) can be used for more flexible filtering options. Multiple filters delimited by semicolons are also supported.

For example, you have an input directory with a variety of file types. To limit the possible matches to only .jpg files, , use a value of *.jpg. To limit the possible matches to only .pdf and .doc files, use a value of *.pdf; *.doc.

To limit possible matches to only file names that contain the text arc, use a value of *arc*.

String
Store Relative Path
(Optional)

Specifies whether the output match table field FILENAME will contain full paths or only the file names.

  • Checked—The field will contain only the file names (relative paths). This is the default.
  • Unchecked—The field will contain full paths to the data.

Boolean
Match Pattern
(Optional)

Specifies the type of match pattern that will be used to match file names with the specified Key Field parameter value.

  • ExactFile names that are an exact match to the values in the key field will be matched. This is the default.
  • PrefixFile names that have the key field value at the beginning of the file name will be matched.
  • SuffixFile names that have the key field value at the end of the file name will be matched.
  • AnyFile names that have the key field value anywhere in the file name will be matched.
String

arcpy.management.GenerateAttachmentMatchTable(in_dataset, in_folder, out_match_table, in_key_field, {in_file_filter}, {in_use_relative_paths}, {match_pattern})
NameExplanationData Type
in_dataset

A dataset containing records that will have files attached.

Table View
in_folder

A folder containing files to attach.

Folder
out_match_table

The output match table with the MATCHID and FILENAME fields.

Table
in_key_field

The field from which values will be used to match the names of the files from the input folder. The matching behavior will compare field values with each file name, disregarding the file extension. This allows multiple files with various file extensions to match a single record in the input dataset.

For example, a field value of lot5986 will match a file named lot5986.jpg if the match_pattern parameter value is EXACT.

Field
in_file_filter
(Optional)

A data filter that will be used to limit the files considered for matching.

Wild cards (*) can be used for more flexible filtering options. Multiple filters delimited by semicolons are also supported.

For example, you have an input directory with a variety of file types. To limit the possible matches to only .jpg files, , use a value of *.jpg. To limit the possible matches to only .pdf and .doc files, use a value of *.pdf; *.doc.

To limit possible matches to only file names that contain the text arc, use a value of *arc*.

String
in_use_relative_paths
(Optional)

Specifies whether the output match table field FILENAME will contain full paths or only the file names.

  • RELATIVEThe field will contain only the file names (relative paths). This is the default.
  • ABSOLUTEThe field will contain full paths.
Boolean
match_pattern
(Optional)

Specifies the type of match pattern that will be used to match file names with the specified key_field parameter value.

  • EXACTFile names that are an exact match to the values in the key field will be matched. This is the default.
  • PREFIXFile names that have the key field value at the beginning of the file name will be matched.
  • SUFFIXFile names that have the key field value at the end of the file name will be matched.
  • ANYFile names that have the key field value anywhere in the file name will be matched.
String

Code sample

GenerateAttachmentMatchTable example 1 (Python window)

The following code snippet demonstrates how to use the GenerateAttachmentMatchTable function in the Python window.

import arcpy
arcpy.management.GenerateAttachmentMatchTable(
    "C:/data/parcels.gdb/parcels",
    "C:/attachment_folder",
    "C:/data/temp.gdb/matchtable",
    "AttachmentKeyField",
    "*.jpg; *.pdf",
    "ABSOLUTE",
    "EXACT")
GenerateAttachmentMatchTable example 2 (stand-alone script)

The following stand-alone script demonstrates how to use the GenerateAttachmentMatchTable function to create a match table that contains matches for .jpg and .pdf files.

# Name: GenerateAttachmentMatchTable_Example.py
# Description: Create an attachment match table for all files that contain the string
# 'property' and are of type 'jpg' while looping through multiple folders.

# Import system modules
import arcpy
import os

# Set local variables.
rootFolder = 'c:/work/'

for folder in os.walk(rootFolder):
    # Exclude file geodatabases from the folder list.
    if folder[0].find('.gdb') == -1:
        arcpy.management.GenerateAttachmentMatchTable(
            "C:/data/parcels.gdb/parcels", folder[0], 
            "C:/data/temp.gdb/matchtable", "AttachmentKeyField", 
            "*property*.jpg", "RELATIVE", "EXACT")

Environments

This tool does not use any geoprocessing environments.

Licensing information

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

Related topics