<?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: Cannot Delete SDE Feature Attachments in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/cannot-delete-sde-feature-attachments/m-p/1043972#M60673</link>
    <description>&lt;P&gt;It looks like you are writing out the the attachment (?) to a file during the process.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From what I can't tell is whether you want to actually delete a file that is used as an attachment.&amp;nbsp; All you are doing in that script is deleting the reference to the name.&amp;nbsp; I would suspect that you have to delete using the "os" module&lt;/P&gt;</description>
    <pubDate>Mon, 05 Apr 2021 20:13:57 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-04-05T20:13:57Z</dc:date>
    <item>
      <title>Cannot Delete SDE Feature Attachments</title>
      <link>https://community.esri.com/t5/python-questions/cannot-delete-sde-feature-attachments/m-p/1041989#M60599</link>
      <description>&lt;P&gt;I have a script that exports and renames photo attachments from an sde feature class. I need to delete the existing attachments each time the script runs, but I can't get it to work. I've tried&amp;nbsp;&lt;SPAN&gt;arcpy.RemoveAttachments_management and del Attachment, but they persist.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Mar 2021 16:13:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-delete-sde-feature-attachments/m-p/1041989#M60599</guid>
      <dc:creator>LeviCecil</dc:creator>
      <dc:date>2021-03-30T16:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Delete SDE Feature Attachments</title>
      <link>https://community.esri.com/t5/python-questions/cannot-delete-sde-feature-attachments/m-p/1042632#M60605</link>
      <description>&lt;P&gt;Are you getting errors? or is it a permissions thing?&lt;/P&gt;&lt;P&gt;Did you try the alternate method described in the Usage section?&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/remove-attachments.htm" target="_blank"&gt;Remove Attachments (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 21:34:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-delete-sde-feature-attachments/m-p/1042632#M60605</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-03-31T21:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Delete SDE Feature Attachments</title>
      <link>https://community.esri.com/t5/python-questions/cannot-delete-sde-feature-attachments/m-p/1043860#M60670</link>
      <description>&lt;P&gt;Hi Dan,&lt;/P&gt;&lt;P&gt;I did not get any errors. Here is what I tried when the remove attachment tool didn't work. This also did not work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;attach_table = 'CustodianInspection__ATTACH'

##Step 1 -Search the atttachment table and export as jpegs with REL_GUID in filename

with da.SearchCursor(attach_table, ['DATA', 'ATT_NAME', 'REL_GLOBALID']) as cursor:
    
    for item in cursor:
        attachment = item[0]
        file_GUID = "GUID_" + str(item[2])
        filename = file_GUID + str(item[1])
        open(temp_dir + os.sep + filename, 'wb').write(attachment.tobytes())

        del item
        del attachment&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 17:03:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-delete-sde-feature-attachments/m-p/1043860#M60670</guid>
      <dc:creator>LeviCecil</dc:creator>
      <dc:date>2021-04-05T17:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Delete SDE Feature Attachments</title>
      <link>https://community.esri.com/t5/python-questions/cannot-delete-sde-feature-attachments/m-p/1043972#M60673</link>
      <description>&lt;P&gt;It looks like you are writing out the the attachment (?) to a file during the process.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From what I can't tell is whether you want to actually delete a file that is used as an attachment.&amp;nbsp; All you are doing in that script is deleting the reference to the name.&amp;nbsp; I would suspect that you have to delete using the "os" module&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 20:13:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-delete-sde-feature-attachments/m-p/1043972#M60673</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-04-05T20:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Delete SDE Feature Attachments</title>
      <link>https://community.esri.com/t5/python-questions/cannot-delete-sde-feature-attachments/m-p/1043984#M60675</link>
      <description>&lt;P&gt;Hey Dan,&lt;/P&gt;&lt;P&gt;Yes, we're exporting the attachments daily to files in directories by site and date taken. What I want to do is clear out the attachment table each time the script runs. Otherwise I'm rewriting these every time the script runs and there are new photo attachments.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 20:42:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-delete-sde-feature-attachments/m-p/1043984#M60675</guid>
      <dc:creator>LeviCecil</dc:creator>
      <dc:date>2021-04-05T20:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Delete SDE Feature Attachments</title>
      <link>https://community.esri.com/t5/python-questions/cannot-delete-sde-feature-attachments/m-p/1044108#M60690</link>
      <description>&lt;P&gt;If you only want to delete the attachments, but keep the features they are attached to:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;attach_table = 'CustodianInspection__ATTACH'

##Step 1 -Search the atttachment table and export as jpegs with REL_GUID in filename

## Use UpdateCursor instead of SearchCursor
with da.UpdateCursor(attach_table, ['DATA', 'ATT_NAME', 'REL_GLOBALID']) as cursor:
    
    for item in cursor:
        attachment = item[0]
        file_GUID = "GUID_" + str(item[2])
        filename = file_GUID + str(item[1])
        open(temp_dir + os.sep + filename, 'wb').write(attachment.tobytes())

        cursor.deleteRow()  # Delete this attachment

        del item
        del attachment&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don't need the features whose attachments you have exported, you can just delete the features and the attachments are deleted automatically.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 09:03:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-delete-sde-feature-attachments/m-p/1044108#M60690</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-04-06T09:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Delete SDE Feature Attachments</title>
      <link>https://community.esri.com/t5/python-questions/cannot-delete-sde-feature-attachments/m-p/1044426#M60697</link>
      <description>&lt;P&gt;That did the trick, thank you! We want to keep the features, as these attachments are pictures of rooms taken by custodians to keep track of issues.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 22:01:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-delete-sde-feature-attachments/m-p/1044426#M60697</guid>
      <dc:creator>LeviCecil</dc:creator>
      <dc:date>2021-04-06T22:01:21Z</dc:date>
    </item>
  </channel>
</rss>

