<?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 Export Attachments from Feature Class in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1253551#M66739</link>
    <description>&lt;P&gt;I have a feature class that has several attachments stored in related tables. I've been trying to use this &lt;A href="https://support.esri.com/en/technical-article/000017450" target="_self"&gt;Export Attachments script&lt;/A&gt; to store the attachments in a local folder, but things aren't working right.&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:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for item in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; attachment = item[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filenum = "ATT" + str(item[2]) + "_"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filename = filenum + str(item[1])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del item
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del filenum
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del filename
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del attachment&lt;/PRE&gt;&lt;P&gt;The tool runs successfully with no errors or warnings. My output location remains empty though. I was thinking that it might just be an indexing issue. This is my attachment table.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JeremyBarnby1_0-1675200252730.png" style="width: 707px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61766i0E846F1F768E3C4B/image-dimensions/707x34?v=v2" width="707" height="34" role="button" title="JeremyBarnby1_0-1675200252730.png" alt="JeremyBarnby1_0-1675200252730.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I've ran the script as is, and I've also ran it by indexing "filenum" to [0] and "filename" to [4], the ATT_NAME field. I've verified that there are actually attachments in the related table. Does anyone know what I could be doing wrong here? Thanks.&lt;/P&gt;&lt;P&gt;EDIT: I just realized that the input and output just indices to the inputs in the tool. Here's what the tool looks like. Running a script like above without putting anything into the tool won't work...unless I hardcode the parameters (having trouble with that too!).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JeremyBarnby1_0-1675434622337.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/62036iF42E9CF37549381B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JeremyBarnby1_0-1675434622337.png" alt="JeremyBarnby1_0-1675434622337.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Feb 2023 14:31:18 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2023-02-03T14:31:18Z</dc:date>
    <item>
      <title>Export Attachments from Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1253551#M66739</link>
      <description>&lt;P&gt;I have a feature class that has several attachments stored in related tables. I've been trying to use this &lt;A href="https://support.esri.com/en/technical-article/000017450" target="_self"&gt;Export Attachments script&lt;/A&gt; to store the attachments in a local folder, but things aren't working right.&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:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for item in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; attachment = item[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filenum = "ATT" + str(item[2]) + "_"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filename = filenum + str(item[1])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del item
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del filenum
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del filename
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del attachment&lt;/PRE&gt;&lt;P&gt;The tool runs successfully with no errors or warnings. My output location remains empty though. I was thinking that it might just be an indexing issue. This is my attachment table.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JeremyBarnby1_0-1675200252730.png" style="width: 707px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61766i0E846F1F768E3C4B/image-dimensions/707x34?v=v2" width="707" height="34" role="button" title="JeremyBarnby1_0-1675200252730.png" alt="JeremyBarnby1_0-1675200252730.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I've ran the script as is, and I've also ran it by indexing "filenum" to [0] and "filename" to [4], the ATT_NAME field. I've verified that there are actually attachments in the related table. Does anyone know what I could be doing wrong here? Thanks.&lt;/P&gt;&lt;P&gt;EDIT: I just realized that the input and output just indices to the inputs in the tool. Here's what the tool looks like. Running a script like above without putting anything into the tool won't work...unless I hardcode the parameters (having trouble with that too!).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JeremyBarnby1_0-1675434622337.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/62036iF42E9CF37549381B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JeremyBarnby1_0-1675434622337.png" alt="JeremyBarnby1_0-1675434622337.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 14:31:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1253551#M66739</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-02-03T14:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: Export Attachments from Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1253611#M66742</link>
      <description>&lt;P&gt;Seems to be working just fine for me as is.&lt;/P&gt;&lt;P&gt;Might be something to do with your path/locations.&amp;nbsp; You could try hard coding the paths and see if that resolves the issue.&amp;nbsp; Then, at least you know where it is going wrong.&lt;/P&gt;&lt;P&gt;Also, make sure you are pointing the search cursor at the attachment table and not the feature class.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;fileLocation = r'C:\tmp\Attachments'                       # folder where attachments are saved
inTable = r'Database Connections\SignsDatabase.sde\SignsDatabase.DBO.Signs__ATTACH'   #  attachment table for feature class&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, can't see the full ATT_NAME in your table, but looks like it could be long with multiple characters.&lt;/P&gt;&lt;P&gt;Want to make sure the final path/filename are still valid filenames within windows.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 23:58:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1253611#M66742</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-01-31T23:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Export Attachments from Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1253750#M66747</link>
      <description>&lt;P&gt;Does your ATT_NAME include the file extension at the end?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 12:54:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1253750#M66747</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-02-01T12:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: Export Attachments from Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1254007#M66754</link>
      <description>&lt;P&gt;Yeah, all the ATT_NAMEs have extensions at the end. There is one attachment table that's empty, but I haven't been able to get the code to extract the files even on the tables that actually have attachments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 18:53:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1254007#M66754</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-02-01T18:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: Export Attachments from Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1254012#M66755</link>
      <description>&lt;P&gt;If you put some print statements in there, what is is saying for:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;print inTable
print fileLocation + os.sep + filename&lt;/LI-CODE&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 19:11:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1254012#M66755</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-02-01T19:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: Export Attachments from Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1254032#M66756</link>
      <description>&lt;P&gt;I've hard coded the paths in there with raw string file paths, and now I'm getting a runtime error saying that it can't open my attachment table.&lt;BR /&gt;&lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt;File "C:/Users/UserName/Documents/Projects/Scripts/ExportAttachments.py", line 11, in &amp;lt;module&amp;gt;&lt;BR /&gt;with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID']) as cursor:&lt;BR /&gt;RuntimeError: cannot open 'C:\Users\UserName\Documents\Projects\MI Green Schools Export\5b060c49-050b-40fa-938b-542ca0ec171b.gdb'&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 19:52:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1254032#M66756</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-02-01T19:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: Export Attachments from Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1254042#M66757</link>
      <description>&lt;P&gt;I only see that error when inTable is set to the FGDB and not to the attachment table itself.&lt;/P&gt;&lt;P&gt;Does adding the path to the actual attachment table make a difference?&lt;/P&gt;&lt;P&gt;print inTable right before the cursor would show you what it is actually using.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;inTable = r'C:\Users\UserName\Documents\Projects\MI Green Schools Export\5b060c49-050b-40fa-938b-542ca0ec171b.gdb\tablename__ATTACH'&lt;/LI-CODE&gt;&lt;P&gt;Don't think it would make a difference with anything here put the print statements, but are you running python 2.7 or 3.x?&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 20:12:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1254042#M66757</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-02-01T20:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: Export Attachments from Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1254044#M66758</link>
      <description>&lt;P&gt;Printing the inTable points to the .gdb of the attachment table. I can't print the filename because it's nested within the for loop and the code needs to access the attachment table in order for the filename to be generated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 20:14:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1254044#M66758</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-02-01T20:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: Export Attachments from Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1254046#M66759</link>
      <description>&lt;P&gt;Python 2 or 3?&lt;/P&gt;&lt;P&gt;Sounds like all you need to do is update inTable to point to the actually attachments table (Not the .gdb) and should be good to go.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy
from arcpy import da
import os

inTable = arcpy.GetParameterAsText(0)
fileLocation = arcpy.GetParameterAsText(1)

print inTable    #  for python 2.7
print(inTable)   # for python 3

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])

        print fileLocation + os.sep + filename  # python 2.7
        print(fileLocation + os.sep + filename)  # python 3

        open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())
        del item
        del filenum
        del filename
        del attachment&lt;/LI-CODE&gt;&lt;P&gt;If not, you can add print statements to the code as above. This will have access to the variable within the loop.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 20:21:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-attachments-from-feature-class/m-p/1254046#M66759</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-02-01T20:21:01Z</dc:date>
    </item>
  </channel>
</rss>

