<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Attach pdf to points in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/attach-pdf-to-points/m-p/1219612#M65763</link>
    <description>&lt;P&gt;One thing I experienced with AddAttachments was, I had fixed some file paths to about 20 records, selected those records and reran the tool.&amp;nbsp; However, AddAttachments appeared to have ignored my selection and&amp;nbsp;&lt;EM&gt;reattached&lt;/EM&gt; all 12,000 of the connected files to my feature class.&amp;nbsp; Not fun.&amp;nbsp; I wondered why that particular tool worked differently.&lt;/P&gt;</description>
    <pubDate>Thu, 06 Oct 2022 21:10:52 GMT</pubDate>
    <dc:creator>RogerDunnGIS</dc:creator>
    <dc:date>2022-10-06T21:10:52Z</dc:date>
    <item>
      <title>Attach pdf to points</title>
      <link>https://community.esri.com/t5/python-questions/attach-pdf-to-points/m-p/1213084#M65582</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am new to python in ArcGIS pro and I am trying to automate our workflow. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to upload pdf attachments to more than 500 points - doing this manually takes hours and hours of work. I need help with writing a code that selects these 500 points and upload the pdf attachments that I have on my computer.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The pdf file name and one of the attributes of the point layer ("Name") are the same. For example, if the one of the points is named “HH NWLD 1.2-3.4" I would like this code to attach the pdf called "HH NWLD 1.2-3.4" from my machine.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is this something possible? Can a code attach pdf files to a feature? I appreciate your input on this.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 18:54:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/attach-pdf-to-points/m-p/1213084#M65582</guid>
      <dc:creator>arifkhan</dc:creator>
      <dc:date>2022-09-15T18:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Attach pdf to points</title>
      <link>https://community.esri.com/t5/python-questions/attach-pdf-to-points/m-p/1213105#M65583</link>
      <description>&lt;P&gt;You may want to look at the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/an-overview-of-the-attachments-toolset.htm" target="_self"&gt;attachment toolset.&lt;/A&gt;&amp;nbsp; You can generate a match table with the point name/pdf path/name and feed that to the add attachments tool to accomplish this.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 19:39:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/attach-pdf-to-points/m-p/1213105#M65583</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-09-15T19:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Attach pdf to points</title>
      <link>https://community.esri.com/t5/python-questions/attach-pdf-to-points/m-p/1213129#M65585</link>
      <description>&lt;P&gt;Also you need to consider if you want to attach the pdf (makes a copy and stores it in the db) using the attachment toolset that Rhett mentioned, or attach a link to the pdf and use a web shared folder/ shared network folder that people can get to.&lt;/P&gt;&lt;P&gt;What are your storage options for this shapefile?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 20:17:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/attach-pdf-to-points/m-p/1213129#M65585</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-09-15T20:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: Attach pdf to points</title>
      <link>https://community.esri.com/t5/python-questions/attach-pdf-to-points/m-p/1215835#M65682</link>
      <description>&lt;P&gt;I would like to store the pdf in the gdb.&lt;/P&gt;&lt;P&gt;I have enabled the attachment for the point layer, so I am trying to figure out the matching attachment table.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Sep 2022 03:42:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/attach-pdf-to-points/m-p/1215835#M65682</guid>
      <dc:creator>arifkhan</dc:creator>
      <dc:date>2022-09-25T03:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Attach pdf to points</title>
      <link>https://community.esri.com/t5/python-questions/attach-pdf-to-points/m-p/1216218#M65684</link>
      <description>&lt;P&gt;Edit to remove some info that did pertain to updating attachments.&lt;/P&gt;&lt;P&gt;You can give this a try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from os import listdir
from os.path import isfile, join
import csv
import arcpy

fc = r'path to the attachments fc'
pdfDir = r'path to pdf directory'

# create a dictionary of pdf files.
pdffiles = {f: {'filePdf': f.split('.')[0], 'filePdfName': f, 'pdfPath': join(pdfDir, f)} for f in listdir(pdfDir) if all([isfile(join(pdfDir, f)), f.endswith('pdf')])}

# add the matching OBJECTID from the featureclass:
# make list of pdf names for the sql query.
pdfs = [k for k in pdffiles.keys()]
# limit the results to the pdfs in the folder and add the objectID to the dictionary.
sql = f"""attach_name IN ({str(pdfs)[1:-1]})"""
with arcpy.da.SearchCursor(fc, ['OBJECTID', 'attach_name'], sql) as sCur:
    for row in sCur:
        pdffiles[row[1]]['OBJECTID'] = row[0]

# convert the pdf file dict to a list of dicts containing the matched objectid and pdf data.
dict_data = [dict(v.items()) for k, v in pdffiles.items()]

# fields to use as the csv header
csv_header = ['OBJECTID', 'filePdf', 'filePdfName', 'pdfPath']

# write the csv
with open(r'match.csv', 'w', newline="") as csvfile:
    writer = csv.DictWriter(csvfile, fieldnames=csv_header)
    writer.writeheader()
    for data in dict_data:
        writer.writerow(data)

# add the attachments
arcpy.management.AddAttachments(fc, 'OBJECTID', 'match.csv', 'OBJECTID', 'pdfPath')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 18:51:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/attach-pdf-to-points/m-p/1216218#M65684</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-09-26T18:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Attach pdf to points</title>
      <link>https://community.esri.com/t5/python-questions/attach-pdf-to-points/m-p/1219612#M65763</link>
      <description>&lt;P&gt;One thing I experienced with AddAttachments was, I had fixed some file paths to about 20 records, selected those records and reran the tool.&amp;nbsp; However, AddAttachments appeared to have ignored my selection and&amp;nbsp;&lt;EM&gt;reattached&lt;/EM&gt; all 12,000 of the connected files to my feature class.&amp;nbsp; Not fun.&amp;nbsp; I wondered why that particular tool worked differently.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 21:10:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/attach-pdf-to-points/m-p/1219612#M65763</guid>
      <dc:creator>RogerDunnGIS</dc:creator>
      <dc:date>2022-10-06T21:10:52Z</dc:date>
    </item>
  </channel>
</rss>

