<?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 Exporting Attachments from a Related Table in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/exporting-attachments-from-a-related-table/m-p/241530#M18790</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does anyone have a script that will download attachments from an sde related table?&amp;nbsp;Ideally the script&amp;nbsp;allow the user to download only the attachments related to a subset of features selected from the original feature class.&amp;nbsp; For example, only download the attachments related to records in the related feature class where "PROJECT" = \'PROJECT NAME\'.&amp;nbsp; I would also like the script to rename to exported files to the ID of the features class + A.&amp;nbsp; For example, feature ID 1234 would export attachments 1234A.jpg and 1234B.jpg.&amp;nbsp; Here's what I have written so far:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy, os&lt;BR /&gt;from collections import defaultdict&lt;/P&gt;&lt;P&gt;inFC = r'Database Connections\LDI_COMPREHENSIVE_WEB_DB.sde\LDI_COMPREHENSIVE_WEB.SDE.WebCollection\LDI_COMPREHENSIVE_WEB.SDE.SurveyPoints' # Feature Class &lt;BR /&gt;inTable = r'Database Connections\LDI_COMPREHENSIVE_WEB_DB.sde\LDI_COMPREHENSIVE_WEB.SDE.SurveyPoints__ATTACH' # Attachment table&lt;BR /&gt;fileLocation = r'W:\Projects\Path' # Output location&lt;/P&gt;&lt;P&gt;# Get dictionary of ObjectID and associated field value&lt;BR /&gt;myFeatures = dict()&lt;BR /&gt;with arcpy.da.SearchCursor(inFC, ['GlobalID', 'Transferred_FacilityID'], '"PROJECT" = \'PROJECT NAME\'') as cursor:&lt;BR /&gt; for row in cursor:&lt;BR /&gt; myFeatures[row[0]] = row[1]&lt;/P&gt;&lt;P&gt;# Create dictionary to count usage of the field value (to increment files)&lt;BR /&gt;valueUsage = defaultdict(int)&lt;/P&gt;&lt;P&gt;# Loop through attachments, incrementing field value usage, and using that&lt;BR /&gt;# increment value in the filename&lt;BR /&gt;with arcpy.da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID', 'REL_GLOBALID']) as cursor:&lt;BR /&gt; for row in cursor:&lt;BR /&gt; if row[3] in myFeatures:&lt;BR /&gt; attachment = row[0]&lt;BR /&gt; fieldValue = myFeatures[row[3]] # Value of specified field in feature class&lt;BR /&gt; valueUsage[fieldValue] += 1 # Increment value&lt;BR /&gt; filename = "{0}_{1}".format(fieldValue, valueUsage[fieldValue]) # filename = FieldValue_1&lt;BR /&gt; output = os.path.join(fileLocation, filename) # Create output filepath&lt;BR /&gt; open(output, 'wb').write(attachment.tobytes()) # Output attachment to file&lt;BR /&gt; del row&lt;BR /&gt; del filename&lt;BR /&gt; del attachment&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help with this would be greatly appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 17 Jun 2019 20:01:32 GMT</pubDate>
    <dc:creator>shildebrand</dc:creator>
    <dc:date>2019-06-17T20:01:32Z</dc:date>
    <item>
      <title>Exporting Attachments from a Related Table</title>
      <link>https://community.esri.com/t5/python-questions/exporting-attachments-from-a-related-table/m-p/241530#M18790</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does anyone have a script that will download attachments from an sde related table?&amp;nbsp;Ideally the script&amp;nbsp;allow the user to download only the attachments related to a subset of features selected from the original feature class.&amp;nbsp; For example, only download the attachments related to records in the related feature class where "PROJECT" = \'PROJECT NAME\'.&amp;nbsp; I would also like the script to rename to exported files to the ID of the features class + A.&amp;nbsp; For example, feature ID 1234 would export attachments 1234A.jpg and 1234B.jpg.&amp;nbsp; Here's what I have written so far:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy, os&lt;BR /&gt;from collections import defaultdict&lt;/P&gt;&lt;P&gt;inFC = r'Database Connections\LDI_COMPREHENSIVE_WEB_DB.sde\LDI_COMPREHENSIVE_WEB.SDE.WebCollection\LDI_COMPREHENSIVE_WEB.SDE.SurveyPoints' # Feature Class &lt;BR /&gt;inTable = r'Database Connections\LDI_COMPREHENSIVE_WEB_DB.sde\LDI_COMPREHENSIVE_WEB.SDE.SurveyPoints__ATTACH' # Attachment table&lt;BR /&gt;fileLocation = r'W:\Projects\Path' # Output location&lt;/P&gt;&lt;P&gt;# Get dictionary of ObjectID and associated field value&lt;BR /&gt;myFeatures = dict()&lt;BR /&gt;with arcpy.da.SearchCursor(inFC, ['GlobalID', 'Transferred_FacilityID'], '"PROJECT" = \'PROJECT NAME\'') as cursor:&lt;BR /&gt; for row in cursor:&lt;BR /&gt; myFeatures[row[0]] = row[1]&lt;/P&gt;&lt;P&gt;# Create dictionary to count usage of the field value (to increment files)&lt;BR /&gt;valueUsage = defaultdict(int)&lt;/P&gt;&lt;P&gt;# Loop through attachments, incrementing field value usage, and using that&lt;BR /&gt;# increment value in the filename&lt;BR /&gt;with arcpy.da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID', 'REL_GLOBALID']) as cursor:&lt;BR /&gt; for row in cursor:&lt;BR /&gt; if row[3] in myFeatures:&lt;BR /&gt; attachment = row[0]&lt;BR /&gt; fieldValue = myFeatures[row[3]] # Value of specified field in feature class&lt;BR /&gt; valueUsage[fieldValue] += 1 # Increment value&lt;BR /&gt; filename = "{0}_{1}".format(fieldValue, valueUsage[fieldValue]) # filename = FieldValue_1&lt;BR /&gt; output = os.path.join(fileLocation, filename) # Create output filepath&lt;BR /&gt; open(output, 'wb').write(attachment.tobytes()) # Output attachment to file&lt;BR /&gt; del row&lt;BR /&gt; del filename&lt;BR /&gt; del attachment&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help with this would be greatly appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Jun 2019 20:01:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-attachments-from-a-related-table/m-p/241530#M18790</guid>
      <dc:creator>shildebrand</dc:creator>
      <dc:date>2019-06-17T20:01:32Z</dc:date>
    </item>
  </channel>
</rss>

