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:
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:
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"
# 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)
# 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])
# the input feature class must first be GDB attachments enabled
# use the match table with the Add Attachments tool
arcpy.AddAttachments_management(input, inputField, matchTable, matchField, pathField, picFolder)
except Exception as err: