<?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 Batch Export Attachments Based On A Definition Query in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/batch-export-attachments-based-on-a-definition/m-p/1137652#M63591</link>
    <description>&lt;P&gt;Hello.&amp;nbsp; Is it possible to run a batch export attachment script that exports based on a definition query assigned to the attachment table?&lt;/P&gt;&lt;P&gt;I was successful in running the script below.&amp;nbsp; However, it exports all photos even though a definition query was applied to the table in the .mxd.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated.&amp;nbsp; Thank you for your time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&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 = "OBJ" + 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;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jan 2022 21:55:36 GMT</pubDate>
    <dc:creator>CWH4</dc:creator>
    <dc:date>2022-01-26T21:55:36Z</dc:date>
    <item>
      <title>Batch Export Attachments Based On A Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/batch-export-attachments-based-on-a-definition/m-p/1137652#M63591</link>
      <description>&lt;P&gt;Hello.&amp;nbsp; Is it possible to run a batch export attachment script that exports based on a definition query assigned to the attachment table?&lt;/P&gt;&lt;P&gt;I was successful in running the script below.&amp;nbsp; However, it exports all photos even though a definition query was applied to the table in the .mxd.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated.&amp;nbsp; Thank you for your time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&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 = "OBJ" + 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;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 21:55:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/batch-export-attachments-based-on-a-definition/m-p/1137652#M63591</guid>
      <dc:creator>CWH4</dc:creator>
      <dc:date>2022-01-26T21:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Batch Export Attachments Based On A Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/batch-export-attachments-based-on-a-definition/m-p/1137670#M63592</link>
      <description>&lt;P&gt;&lt;STRIKE&gt;It doesn't&amp;nbsp; work with Definition queries on the Feature Class, but a workaround is select by attributes--&amp;gt; Export attachments.&lt;/STRIKE&gt; Whoops, that behaviour is script-dependent, I think. Selecting narrows it down on a script that I've written but not on another one I tested.&lt;/P&gt;&lt;P&gt;Alternatively, you could come up a definition query on the Attachments table, but that's probably a lot more trouble than it's worth.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 22:25:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/batch-export-attachments-based-on-a-definition/m-p/1137670#M63592</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-01-26T22:25:45Z</dc:date>
    </item>
    <item>
      <title>Re: Batch Export Attachments Based On A Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/batch-export-attachments-based-on-a-definition/m-p/1137824#M63597</link>
      <description>&lt;P&gt;You'll need to put the definition query in the where_clause parameter spot in your search cursor for it to only get those attachments.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;where_clause = 'your def query'
with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID'], where_clause) as cursor:
    for item in cursor:
        attachment = item[0]
        filenum = "OBJ" + str(item[2]) + "_"
        filename = filenum + str(item[1])
        open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 12:17:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/batch-export-attachments-based-on-a-definition/m-p/1137824#M63597</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-01-27T12:17:36Z</dc:date>
    </item>
  </channel>
</rss>

