<?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: Deleting features, tables, datasets from database not working correctly in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249912#M66606</link>
    <description>&lt;P&gt;Don't know what to tell you.&amp;nbsp; If you add a precondition like I did in the example above so that the delete has to succeed before the create, then there is no way it could still exist unless you are working on different datasets or maybe some lock files are in place (though, shouldn't succeed in the delete if that is the case).&lt;/P&gt;&lt;P&gt;What happens if you make a new model with the delete tool, then create tool?&amp;nbsp; If that works, there is something else going on in the model/code somewhere.&lt;/P&gt;&lt;P&gt;Also, sometimes it helps to export the model to a python file as it can make it easier to see/notice path mismatches and such.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Jan 2023 15:36:52 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2023-01-20T15:36:52Z</dc:date>
    <item>
      <title>Deleting features, tables, datasets from database not working correctly</title>
      <link>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249574#M66592</link>
      <description>&lt;P&gt;I am trying to delete all feature classes, tables and datasets from a file database and the issue is sometimes it works and sometimes it doesn't. I trying the following but none of them works consistently. My thought is that, os.path.exists would be more reliable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os
def deletePI():   
    try:
        arcpy.env.workspace = "C:/Temp/DashboardPI.gdb"
        fc_list = arcpy.ListFeatureClasses()
        tables = arcpy.ListTables()
        ds_list = arcpy.ListDatasets()

        #feature classes
        for fc in fc_list:
            arcpy.Delete_management(fc)

        #tables
        for table in tables:
            arcpy.Delete_management(table)

        #data sets
        for ds in ds_list:
            arcpy.Delete_management(ds)

    except:
        pass&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os

def deletePI():    
    try:
        arcpy.env.workspace = "C:/Temp/DashboardPI.gdb"
        
        if os.path.exists("C:/Temp/BoardPI.gdb/PI_Taxp") == True:
            arcpy.Delete_management(r"C:/Temp/boardPI.gdb/PI_Taxp")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 17:48:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249574#M66592</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2023-01-19T17:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting features, tables, datasets from database not working correctly</title>
      <link>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249595#M66594</link>
      <description>&lt;P&gt;In windows explorer, examine the&amp;nbsp;"C:/Temp/BoardPI.gdb" and you won't find a file called "PI_Taxp" since featureclass naming is handled by Pro&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 18:14:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249595#M66594</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-01-19T18:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting features, tables, datasets from database not working correctly</title>
      <link>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249656#M66595</link>
      <description>&lt;P&gt;So, are you still seeing datasets in there with Pro after the delete?&amp;nbsp; Windows explorer will show a bunch of files in an "empty" FGDB, so can't tell using that if it worked or not.&lt;/P&gt;&lt;P&gt;And, are you trying to just preserve domains or something?&lt;/P&gt;&lt;P&gt;If not, would be quicker to just delete the FGDB and create a new one with the same name.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 19:39:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249656#M66595</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-01-19T19:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting features, tables, datasets from database not working correctly</title>
      <link>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249685#M66596</link>
      <description>&lt;P&gt;I am trying to using this in a Calculate Value tool.&lt;/P&gt;&lt;P&gt;I am still seeing the datasets in there with Pro and I do see a bunch of files in the FGDB through Windows explorer.&lt;/P&gt;&lt;P&gt;The odd thing that I noticed is if I select the Calculate Value Tool in the Model Builder View window, right click and select run, its runs fine, everything gets deleted. If I right click on the Scheduled Model&amp;nbsp;with this Calculate Value Tool in the Scheduled Tools window and selecting run,&amp;nbsp;I get a warning that, "PI_Taxp" already exists in the C:/Temp/BoardPI.gdb". So it's not being deleted.&lt;/P&gt;&lt;P&gt;So it appears that if it's scheduled in a Pro project, it doesn't run...?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CCWeedcontrol_0-1674160912392.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60783i98CBCB188CAA1036/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CCWeedcontrol_0-1674160912392.png" alt="CCWeedcontrol_0-1674160912392.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CCWeedcontrol_1-1674160925645.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60784iEEDB29B316E12A21/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CCWeedcontrol_1-1674160925645.png" alt="CCWeedcontrol_1-1674160925645.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 20:42:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249685#M66596</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2023-01-19T20:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting features, tables, datasets from database not working correctly</title>
      <link>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249695#M66597</link>
      <description>&lt;P&gt;Don't see the Calculate Value tool, that must be something custom?&amp;nbsp; Not sure what is going on there.&lt;/P&gt;&lt;P&gt;Didn't say why you need to delete everything from FGDB, is there a reason you can't just clobber it, then feed the new, empty FGDB to the rest of the tools?&amp;nbsp; Much faster/cleaner method to "empty" a FGDB.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RhettZufelt_0-1674161740167.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60786iB8B9A6F248CAF0E6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RhettZufelt_0-1674161740167.png" alt="RhettZufelt_0-1674161740167.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 20:56:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249695#M66597</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-01-19T20:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting features, tables, datasets from database not working correctly</title>
      <link>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249698#M66598</link>
      <description>&lt;P&gt;Could it be that the code you supplied is deleting it from&amp;nbsp;C:/Temp/DashboardPI.gdb, but the message says it still exists in the&amp;nbsp;C:/Temp/BoardPI.gdb&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 20:59:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249698#M66598</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-01-19T20:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting features, tables, datasets from database not working correctly</title>
      <link>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249713#M66599</link>
      <description>&lt;P&gt;I guess there is not in this particular situation, I could delete the geodatabase with the delete tool and then create a new one.&lt;/P&gt;&lt;P&gt;I would still like to know why it's not delete with the Calculate Value Tool, if I run it through the task scheduler in Pro.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 21:29:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249713#M66599</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2023-01-19T21:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting features, tables, datasets from database not working correctly</title>
      <link>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249716#M66600</link>
      <description>&lt;P&gt;Without knowing what is in the calculate value tool (which seems to suggest it calculates a value, not deletes stuff) couldn't really speculate, as long as you got the correct FGDB's (since you mix the two in previous posts).&lt;/P&gt;&lt;P&gt;One thought, though not sure how it works in Model builder, vs straight python) if you are using something that only works on feature layers (a lot of the GP tools) and not directly on featureclasses, if you set it up in pro and select the data from the drop down menu, it is automatically loading a feature layer in the tool, not a feature class.&amp;nbsp; So, if run outside of that "open" Pro project, these types of tools will fail (Not sure if tasks scheduled through Pro actually open the document, or just runs in python outside of Pro).&lt;/P&gt;&lt;P&gt;This is one of the main reasons I've run into where it will run in Pro/Map, but not stand alone.&lt;/P&gt;&lt;P&gt;You could test if this is what is going on my using the Make Feature Layer tool on each dataset, then use the resultant feature layer in the tool, rather than the FC itself.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 21:39:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249716#M66600</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-01-19T21:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting features, tables, datasets from database not working correctly</title>
      <link>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249905#M66604</link>
      <description>&lt;P&gt;After setting up the model to use the delete tool and create file geodatabase tool, then scheduling it to run this morning, I get the warnings, the geodatabase already exists and so does the PI_Tax feature class. So nothing was deleted.&lt;/P&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;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CCWeedcontrol_1-1674227894309.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60836iABE644C1346FC993/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CCWeedcontrol_1-1674227894309.png" alt="CCWeedcontrol_1-1674227894309.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 15:19:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249905#M66604</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2023-01-20T15:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting features, tables, datasets from database not working correctly</title>
      <link>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249912#M66606</link>
      <description>&lt;P&gt;Don't know what to tell you.&amp;nbsp; If you add a precondition like I did in the example above so that the delete has to succeed before the create, then there is no way it could still exist unless you are working on different datasets or maybe some lock files are in place (though, shouldn't succeed in the delete if that is the case).&lt;/P&gt;&lt;P&gt;What happens if you make a new model with the delete tool, then create tool?&amp;nbsp; If that works, there is something else going on in the model/code somewhere.&lt;/P&gt;&lt;P&gt;Also, sometimes it helps to export the model to a python file as it can make it easier to see/notice path mismatches and such.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 15:36:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/deleting-features-tables-datasets-from-database/m-p/1249912#M66606</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-01-20T15:36:52Z</dc:date>
    </item>
  </channel>
</rss>

