<?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: Please help with batch exporting photo attachments in Field Maps in ArcGIS Field Maps Questions</title>
    <link>https://community.esri.com/t5/arcgis-field-maps-questions/please-help-with-batch-exporting-photo-attachments/m-p/1210019#M4431</link>
    <description>&lt;P&gt;Looks like your code keeps naming all the photos the same name this will overwrite it each time so you just get 1.&amp;nbsp; In 123 I have a field that calcs my photo name for me then I use that.&amp;nbsp; You could add a field with Arcade to do that or you could just have the script query the output dir and get the number of files then add 1 and append that to you export name.&amp;nbsp; (assuming not other stuff in the folder)&lt;/P&gt;&lt;P&gt;Something like (I did not check syntax but you get the idea).&lt;/P&gt;&lt;P&gt;numberToUse = count(os.listdir(fileLocation)) + 1&lt;/P&gt;&lt;P&gt;open(fileLocation + os.sep + origName + str(numberToUse) + ".jpg",'wb').write(binaryRep.tobytes())&lt;/P&gt;&lt;P&gt;Hope that helps&lt;/P&gt;&lt;P&gt;My script is here&amp;nbsp;&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-survey123-questions/match-survey123-photo-attachments-to-feature-in/m-p/1030224" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-survey123-questions/match-survey123-photo-attachments-to-feature-in/m-p/1030224&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I then create HTML pages in the dir with this&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-survey123-questions/best-practices-for-survey123-photo-storage/m-p/1083035" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-survey123-questions/best-practices-for-survey123-photo-storage/m-p/1083035&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Sep 2022 18:30:55 GMT</pubDate>
    <dc:creator>DougBrowning</dc:creator>
    <dc:date>2022-09-06T18:30:55Z</dc:date>
    <item>
      <title>Please help with batch exporting photo attachments in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/please-help-with-batch-exporting-photo-attachments/m-p/1209588#M4426</link>
      <description>&lt;P&gt;&lt;STRONG&gt;I would like to batch export my photo attachments from Field Maps on my local network. I need an efficient way to have multiples photos that are associated with a single survey be named in a way that lets me know what survey&amp;nbsp;they're tied to. I have discovered a couple of scripts for ArcGIS Collector that batch export the attachments to my local folder, but the script only address one attachment per&amp;nbsp;survey. I believe this happens because the script is written in a way that it assumes the attachment table is a one-to-one with the feature layer. I typically have a couple of photos per record and my surveys entail hundreds of records. I am able to get the first attachment exported with appropriate names but the script ignores a second or a third attachment for the same record. Would anyone be able to help me with a complete script that exports all photo attachments for each record?&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;This is the script that I have been using:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;# imports the necessary modules to run&lt;BR /&gt;from arcpy import da&lt;BR /&gt;import os&lt;/P&gt;&lt;P&gt;attachTable = arcpy.GetParameterAsText(0) # table in GDB holding attachments&lt;BR /&gt;origTable = arcpy.GetParameterAsText(1) # layer in GDB holding features to which attachments belong&lt;BR /&gt;nameField = arcpy.GetParameterAsText(2) # field in origTable that contains more appropriate name for attachment&lt;BR /&gt;fileLocation = arcpy.GetParameterAsText(3) # folder where you want to save the photos&lt;/P&gt;&lt;P&gt;# create the cursor to search through the attachment tables; specify you only wish to search those three fields&lt;BR /&gt;attachCursor = da.SearchCursor(attachTable,['DATA','ATT_NAME','REL_GLOBALID'])&lt;/P&gt;&lt;P&gt;# begin searching the table and storing the actual images, movies, etc&lt;BR /&gt;for attRow in attachCursor:&lt;BR /&gt;binaryRep = attRow[0]&lt;BR /&gt;fileName = attRow[1]&lt;BR /&gt;relID = attRow[2] # defines the relationship ID that we can use to join to the actual features (origTable)&lt;/P&gt;&lt;P&gt;# creates a cursor to sort the features; essentially to find a match for the relID above&lt;BR /&gt;originCursor = da.SearchCursor(origTable,['GlobalID', nameField])&lt;BR /&gt;for origRow in originCursor:&lt;BR /&gt;origID = origRow[0] # store the Global ID (which will match to the relID above for the correct attachment)&lt;BR /&gt;origName = origRow[1] # store the unique name of each record that you will use to save the attachment&lt;BR /&gt;if origID == relID: # stops the search after it finds the record which equals the ID from the attachments&lt;BR /&gt;break&lt;/P&gt;&lt;P&gt;# saves a file in the specified location that contains the name chosen by the user for that attachment&lt;BR /&gt;open(fileLocation + os.sep + origName + ".jpg",'wb').write(binaryRep.tobytes())&lt;/P&gt;&lt;P&gt;# iteratively deletes the searchCursor from the feature class so it can reboot for the next attachment!&lt;BR /&gt;del originCursor&lt;/P&gt;&lt;P&gt;# If you are creating script from Sratch in ArcGIS&lt;BR /&gt;# Parameter(0) Type = Table&lt;BR /&gt;# Parameter(1) Type = Feature Layer&lt;BR /&gt;# Parameter(2) Type = Field (obtained from Parameter(1)&lt;BR /&gt;# Parameter(3) Type = Folder (make sure it is an input)&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2022 00:27:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/please-help-with-batch-exporting-photo-attachments/m-p/1209588#M4426</guid>
      <dc:creator>SamRycken</dc:creator>
      <dc:date>2022-09-05T00:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: Please help with batch exporting photo attachments in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/please-help-with-batch-exporting-photo-attachments/m-p/1210019#M4431</link>
      <description>&lt;P&gt;Looks like your code keeps naming all the photos the same name this will overwrite it each time so you just get 1.&amp;nbsp; In 123 I have a field that calcs my photo name for me then I use that.&amp;nbsp; You could add a field with Arcade to do that or you could just have the script query the output dir and get the number of files then add 1 and append that to you export name.&amp;nbsp; (assuming not other stuff in the folder)&lt;/P&gt;&lt;P&gt;Something like (I did not check syntax but you get the idea).&lt;/P&gt;&lt;P&gt;numberToUse = count(os.listdir(fileLocation)) + 1&lt;/P&gt;&lt;P&gt;open(fileLocation + os.sep + origName + str(numberToUse) + ".jpg",'wb').write(binaryRep.tobytes())&lt;/P&gt;&lt;P&gt;Hope that helps&lt;/P&gt;&lt;P&gt;My script is here&amp;nbsp;&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-survey123-questions/match-survey123-photo-attachments-to-feature-in/m-p/1030224" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-survey123-questions/match-survey123-photo-attachments-to-feature-in/m-p/1030224&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I then create HTML pages in the dir with this&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-survey123-questions/best-practices-for-survey123-photo-storage/m-p/1083035" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-survey123-questions/best-practices-for-survey123-photo-storage/m-p/1083035&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 18:30:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/please-help-with-batch-exporting-photo-attachments/m-p/1210019#M4431</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2022-09-06T18:30:55Z</dc:date>
    </item>
  </channel>
</rss>

