<?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 Python Script Assistance for Renaming Attachments based on related table field in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-assistance-for-renaming-attachments/m-p/1112918#M47376</link>
    <description>&lt;P&gt;Hello! (&amp;amp; Thank you!)&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Using ArcGIS Pro 2.8.3&lt;/P&gt;&lt;P data-unlink="true"&gt;I am wrapping up a survey conducted in survey123, where data was hosted in AGOL. It cannot stay there, and must be downloaded. I have run a test and downloaded the data into a gdb, and I have run the script to batch export the photos (&amp;nbsp; &lt;A href="https://support.esri.com/en/technical-article/000011912" target="_blank"&gt;How To: Batch export attachments from a feature class in ArcMap (esri.com)&lt;/A&gt;&amp;nbsp;&amp;nbsp;)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The issue:&amp;nbsp; the naming of the photo files is long and not user-friendly.&lt;/STRONG&gt; Each photo is from the related table of a survey that is surveying houses/properties. The related table has a 'Full_Address' or 'PIN' (parcel ID) field which would be great for the file name.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;How would I modify the script to put the PIN or Address from the related table instead of say the ATTACHMENTID ? or ATT_NAME?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Script from link above:&lt;/P&gt;&lt;PRE&gt;import arcpy
from arcpy import da
import os

inTable = arcpy.GetParameterAsText(0)
fileLocation = arcpy.GetParameterAsText(1)

with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID']) as cursor:
    for item in cursor:
        attachment = item[0]
        filenum = "ATT" + str(item[2]) + "_"
        filename = filenum + str(item[1])
        open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())
        del item
        del filenum
        del filename
        del attachment&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I have found another resource (below), but my python skills are quite limited at this point and I cannot follow how I would need to adjust what they provide for me to get what I need.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://gis.stackexchange.com/questions/251817/renaming-photo-attachments" target="_blank" rel="noopener"&gt;arcpy - Renaming photo attachments? - Geographic Information Systems Stack Exchange&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Thank you again for taking the time to assist!&lt;/P&gt;</description>
    <pubDate>Mon, 01 Nov 2021 18:16:54 GMT</pubDate>
    <dc:creator>JessicaJThompson</dc:creator>
    <dc:date>2021-11-01T18:16:54Z</dc:date>
    <item>
      <title>Python Script Assistance for Renaming Attachments based on related table field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-assistance-for-renaming-attachments/m-p/1112918#M47376</link>
      <description>&lt;P&gt;Hello! (&amp;amp; Thank you!)&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Using ArcGIS Pro 2.8.3&lt;/P&gt;&lt;P data-unlink="true"&gt;I am wrapping up a survey conducted in survey123, where data was hosted in AGOL. It cannot stay there, and must be downloaded. I have run a test and downloaded the data into a gdb, and I have run the script to batch export the photos (&amp;nbsp; &lt;A href="https://support.esri.com/en/technical-article/000011912" target="_blank"&gt;How To: Batch export attachments from a feature class in ArcMap (esri.com)&lt;/A&gt;&amp;nbsp;&amp;nbsp;)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The issue:&amp;nbsp; the naming of the photo files is long and not user-friendly.&lt;/STRONG&gt; Each photo is from the related table of a survey that is surveying houses/properties. The related table has a 'Full_Address' or 'PIN' (parcel ID) field which would be great for the file name.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;How would I modify the script to put the PIN or Address from the related table instead of say the ATTACHMENTID ? or ATT_NAME?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Script from link above:&lt;/P&gt;&lt;PRE&gt;import arcpy
from arcpy import da
import os

inTable = arcpy.GetParameterAsText(0)
fileLocation = arcpy.GetParameterAsText(1)

with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID']) as cursor:
    for item in cursor:
        attachment = item[0]
        filenum = "ATT" + str(item[2]) + "_"
        filename = filenum + str(item[1])
        open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())
        del item
        del filenum
        del filename
        del attachment&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I have found another resource (below), but my python skills are quite limited at this point and I cannot follow how I would need to adjust what they provide for me to get what I need.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://gis.stackexchange.com/questions/251817/renaming-photo-attachments" target="_blank" rel="noopener"&gt;arcpy - Renaming photo attachments? - Geographic Information Systems Stack Exchange&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Thank you again for taking the time to assist!&lt;/P&gt;</description>
      <pubDate>Mon, 01 Nov 2021 18:16:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-assistance-for-renaming-attachments/m-p/1112918#M47376</guid>
      <dc:creator>JessicaJThompson</dc:creator>
      <dc:date>2021-11-01T18:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script Assistance for Renaming Attachments based on related table field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-assistance-for-renaming-attachments/m-p/1125653#M48992</link>
      <description>&lt;P&gt;&lt;SPAN&gt;You could do something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;originTable = &amp;lt;path&amp;gt;
targetTable = &amp;lt;path&amp;gt;

originData = [row for row in arcpy.da.SearchCursor(originTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID']]
targetData = [row for row in arcpy.da.SearchCursor(targetTable, ['Full_Address', 'PIN']]

for origin_row, target_row in zip(originData, targetData):
    # now do what you did but use target_row[0] or target_row[1] for
    # constructing your filename.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 00:01:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-assistance-for-renaming-attachments/m-p/1125653#M48992</guid>
      <dc:creator>HannesZiegler</dc:creator>
      <dc:date>2021-12-14T00:01:30Z</dc:date>
    </item>
  </channel>
</rss>

