AnsweredAssumed Answered

How to create a match table that has a column which takes in an attribute field's IDs as input?

Question asked by VAZQ_S on Aug 3, 2016
Latest reply on Aug 3, 2016 by Dan_Patterson

I am using ArcGIS Pro.

I have a folder with 198 separate PDF files that I want to link to a feature class (input the pathname into the field.

I have tried creating a Match Table (and enabled the Add Attachments Tool) - the result was a Table with two columns:

 

1) FAC_ID

2) ATTACHMENT

 

I am able to fill the attachment column with the file names and ".pdf" at the end. However, I only want the FAC_ID field entries to be filled with the first 6 characters of the PDF file name. This way I can join the table with the feature class based on the FAC_ID field.

 

Also, I just realized that the end goal is to create hyperlinks from the PDF file names in the attribute table but the attachment field is only taking in the PDF file name and not the pathname.

 

Below is the code I used:

 

import csv

import arcpy

import os

import sys

 

input = r"C:\CSF\CSF.gdb\FeatureClass"

inputField = "FAC_ID"

matchTable = r"C:\Arcpy Scripts\matchtable.csv"

matchField = "FAC_ID"

pathField = "Attachments"

picFolder = r"C:/PDF_Folder"

 

try:

    # create a new Match Table csv file

    writer = csv.writer(open(matchTable, "wt"), 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(".pdf") > -1:

            writer.writerow([str(file).replace(".pdf", ""), 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, inputField, matchTable, matchField, pathField, picFolder)

except Exception as err:

    print(err.args[0])

Outcomes