<?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: Naming images from batch attachment export from a layer field in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1386579#M79280</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/15530"&gt;@RhettZufelt&lt;/a&gt;&amp;nbsp;, that's incredibly helpful thank you.&lt;/P&gt;</description>
    <pubDate>Mon, 26 Feb 2024 01:27:24 GMT</pubDate>
    <dc:creator>AndrewHankinson</dc:creator>
    <dc:date>2024-02-26T01:27:24Z</dc:date>
    <item>
      <title>Naming images from batch attachment export from a layer field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1227629#M61787</link>
      <description>&lt;P&gt;Hi all.&amp;nbsp; I am not good at python at all. I have tried &lt;A href="https://community.esri.com/t5/arcgis-collector-questions/please-help-with-batch-exporting-photo-attachments/m-p/531825" target="_self"&gt;using other codes I found&lt;/A&gt; but am having no luck.&amp;nbsp; I am just not good enough to see what I need to change.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the &lt;A href="https://support.esri.com/en/technical-article/000011912" target="_self"&gt;batch export attachment rules&lt;/A&gt;&amp;nbsp; and created the tool to export out the images but I need to have the images labeled with the asset_number from the layer so we don't have to go through and label each one individually.&lt;/P&gt;&lt;P&gt;I have GlobalID that create the relation between the tables but need the asset_number from the layer to be the actual image file name.&lt;/P&gt;&lt;P&gt;Any ideas?&amp;nbsp;&amp;nbsp; I am working in pro 3.0&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 19:43:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1227629#M61787</guid>
      <dc:creator>SRanseen</dc:creator>
      <dc:date>2022-11-01T19:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: Naming images from batch attachment export from a layer field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1227710#M61794</link>
      <description>&lt;P&gt;Below is what I am using.&amp;nbsp; I don't attach to a tool or anything.&amp;nbsp; I just hard code the feature class with attachments, and the attachemnt table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

inFeatureClass = r'Database Connections\Database.sde\Database.DBO.Signs'         # feature class with attachments
pointFieldsList = ['GlobalID','asset_number']                 # fields to load into cursor

global_dict = {}                                           # dictionary to hold globalIDs and "name" field

fileLocation = r'C:\tmp\Attachments'                       # folder where attachments are saved MAKE SURE FOLDER EXISTS


with arcpy.da.SearchCursor(inFeatureClass, pointFieldsList) as point_cursor:  # cursor to make dict of globalID's
        for row in point_cursor:
          if row[1]:
            row1 = row[1]                                 # I'm using "asset_number" as my name field, but is
          else:                                           # not always populated.  if Null, substitute "NA"
            row1 = "NA"
          global_dict[row[0]] = [row[0],row1]             # add to dict with globallID as key, name as value


inTable = r'Database Connections\Database.sde\Database.DBO.Sign__ATTACH'   #  attachment table for feature class
tableFieldsList = ['REL_GLOBALID', 'DATA', 'ATT_NAME', 'ATTACHMENTID']              # field list in attachment table


with arcpy.da.SearchCursor(inTable, tableFieldsList) as table_cursor:
    for item in table_cursor:
        attachment = item[1]                                                        # grab attachemnt from blob field
        filename = global_dict[item[0]][1] + '_' + str(item[3]) + '.jpg'            # create filename from value in FC dict that has matching GlobalID
                                                                                    # added  '_' + str(item[3]) +  to add attachment ID as many of my names are the same
        open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())    # write the attachment as a file.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If your asset_number is unique for all features, you could delete the "&amp;nbsp; &amp;nbsp;&amp;nbsp; + '_' + str(item[3])&amp;nbsp; &amp;nbsp;" from line 28.&amp;nbsp; That just appends the attachment_id to the filename so that it is unique.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 22:06:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1227710#M61794</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-11-01T22:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Naming images from batch attachment export from a layer field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1227719#M61796</link>
      <description>&lt;P&gt;Thank you I was able to get it to work just running it in a notebook.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 22:43:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1227719#M61796</guid>
      <dc:creator>SRanseen</dc:creator>
      <dc:date>2022-11-01T22:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Naming images from batch attachment export from a layer field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1384779#M79095</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/15530"&gt;@RhettZufelt&lt;/a&gt;&amp;nbsp;this is exactly what I was looking for having just exported a whole host of attachments from a master layer of which none were directly relateable to the features.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have got the script to work so that the attachments exported contain a specific project name, however is it possible to have the exported attachments have a name like this.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Project_name_Feature_ID_AttachmentID.jpg?&lt;BR /&gt;&lt;BR /&gt;I have tried adding in&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;pointFieldsList = ['GlobalID','PROJECT','Feature_ID']&lt;BR /&gt;&lt;BR /&gt;But I'm thinking that I need to add something to the&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;filename = global_dict[item[0]][1] + '_' + str(item[3]) + '.jpg'&lt;BR /&gt;&lt;BR /&gt;Can you help me out?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2024 09:02:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1384779#M79095</guid>
      <dc:creator>AndrewHankinson</dc:creator>
      <dc:date>2024-02-21T09:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Naming images from batch attachment export from a layer field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1384926#M79109</link>
      <description>&lt;P&gt;See &lt;A href="https://community.esri.com/t5/community-help-documents/how-to-insert-code-in-your-post/ta-p/914552" target="_self"&gt;this link&lt;/A&gt; for future code posting.&amp;nbsp; Makes it much easier to follow.&lt;/P&gt;&lt;P&gt;Do you have an attribute for each feature with the project or are all features in the featureclass from the same project?&lt;/P&gt;&lt;P&gt;If they are all the same project and you just want to modify the filename to add the project name to the beginning then this should do it:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;pointFieldsList = ['GlobalID','Feature_ID']
filename = 'ProjName_' + str(global_dict[item[0]][1]) + '_' + str(item[3]) + '.jpg'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2024 15:45:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1384926#M79109</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2024-02-21T15:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Naming images from batch attachment export from a layer field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1385222#M79139</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/15530"&gt;@RhettZufelt&lt;/a&gt;,&amp;nbsp;thanks for getting back to me so quickly.&lt;/P&gt;&lt;P&gt;Sorry I didn't know about that link, only just looking at using scripts in ArcGIS Pro recently. I think I need to set up python as my main script editor as I am currently only using notebooks.&lt;BR /&gt;&lt;BR /&gt;Each feature will have a unique Feature_ID, the feature class is a master layer for multiple projects so there is an additional attribute called 'PROJECT'.&lt;BR /&gt;&lt;BR /&gt;With your script above I can get the PROJECT as the file name followed by the attachment ID, what would be ideal is to have the PROJECT followed by the Feature_ID then thet attachment ID so each attachment can be traced back to the specific feature.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 01:25:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1385222#M79139</guid>
      <dc:creator>AndrewHankinson</dc:creator>
      <dc:date>2024-02-22T01:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: Naming images from batch attachment export from a layer field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1386335#M79238</link>
      <description>&lt;P&gt;this does that.&amp;nbsp; Had to change field name as my test dataset is based on OBJECTID, not GlobalID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy
import os

inFeatureClass = r'Database Connections\database.sde\database.DBO.Imagery_Points_2024'         # feature class with attachments
pointFieldsList = ['OBJECTID','Feature_ID', 'PROJECT']                 # fields to load into cursor

global_dict = {}                                           # dictionary to hold OBJECTID and "name" field

fileLocation = r'C:\tmp\Attachments'                       # folder where attachments are saved MAKE SURE FOLDER EXISTS


with arcpy.da.SearchCursor(inFeatureClass, pointFieldsList) as point_cursor:  # cursor to make dict of OBJECTID's
        for row in point_cursor:
          if row[1]:
            row1 = row[1]                                 # I'm using "Feature_ID" as my name field, but is
          else:                                           # not always populated.  if Null, substitute "NA"
            row1 = "NA"
          global_dict[row[0]] = [row[0],[row1,row[2]]]             # add to dict with OBJECTID as key, name and project as value list


inTable = r'Database Connections\database.sde\database.DBO.Imagery_Points_2024__ATTACH'   #  attachment table for feature class
tableFieldsList = ['REL_OBJECTID', 'DATA', 'ATT_NAME', 'ATTACHMENTID']              # field list in attachment table


with arcpy.da.SearchCursor(inTable, tableFieldsList) as table_cursor:
    for item in table_cursor:
        attachment = item[1]                                                        # grab attachemnt from blob field
        filename = global_dict[item[0]][1][1] + '_' + global_dict[item[0]][1][0] + '_' + str(item[3]) + '.jpg'            # create filename from value in FC dict that has matching OBJECTID
        open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())    # write the attachment as a file.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;basically, it adds a list (Feature_ID, PROJECT) as the value in the dictionary key:value pair.&lt;/P&gt;&lt;P&gt;Then, extract the second value from the pair as the project name, first value of the pair is the Feature_ID.&lt;/P&gt;&lt;P&gt;I'm sure there's a better way to extract multiple values from a dictionary key, but no time to research it.&lt;/P&gt;&lt;P&gt;maybe someone on here can improve it.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2024 21:54:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1386335#M79238</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2024-02-23T21:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Naming images from batch attachment export from a layer field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1386579#M79280</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/15530"&gt;@RhettZufelt&lt;/a&gt;&amp;nbsp;, that's incredibly helpful thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Feb 2024 01:27:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/naming-images-from-batch-attachment-export-from-a/m-p/1386579#M79280</guid>
      <dc:creator>AndrewHankinson</dc:creator>
      <dc:date>2024-02-26T01:27:24Z</dc:date>
    </item>
  </channel>
</rss>

