<?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: How to delete a network analysis dataset via a script? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-delete-a-network-analysis-dataset-via-a/m-p/1049635#M60856</link>
    <description>&lt;P&gt;Have you tried deleting what may exist from a previous run first at the start of your script?&lt;/P&gt;&lt;P&gt;In other words if it "exists" delete it, then proceed on from there. (move your delete management line to the top)&lt;/P&gt;</description>
    <pubDate>Wed, 21 Apr 2021 15:56:51 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-04-21T15:56:51Z</dc:date>
    <item>
      <title>How to delete a network analysis dataset via a script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-a-network-analysis-dataset-via-a/m-p/1049627#M60855</link>
      <description>&lt;P&gt;I am trying to delete the network analysis dataset as part of a workflow, but having no success. Is there an arcpy protocol that can be used to delete the dataset and feature classes? I have attempted to use the arcpy.Delete_management() call with no success.&lt;/P&gt;&lt;P&gt;Did see this in the Data Management - Delete documentation...&lt;BR /&gt;'Feature classes and tables participating in a network analysis dataset or a topology cannot be deleted'&lt;/P&gt;&lt;P&gt;But I can manually delete them from the GDB after I am done with them. But not with a script?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# General workflow...
na_lyr_name = "Service Area"
na_result = arcpy.na.MakeServiceAreaAnalysisLayer(routing_src, na_lyr_name, etc)
arcpy.na.AddLocations(na_lyr_name, etc)
arcpy.na.Solve(na_lyr_name, "SKIP", "TERMINATE", None, '')
na_lyr = na_result[0]

# Go create feature layers off the lines and polygon results of the network analysis...
# Then clean up the now unneeded NA dataset...

# First tried just deleting the dataset itself...
arcpy.Delete_management(na_lyr)
# or...
arcpy.Delete_management(na_lyr_name) 

# Then tried looping through the layers
for lyr in na_lyr.listLayers():
    layer_path = os.path.join(DATA_GDB, lyr.name)    
    temp = arcpy.Delete_management(layer_path)
    # debug...returns True and layer name
    print(temp, lyr.name)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No errors thrown. The 'temp' print statement in there shows the Delete reporting successful. But the dataset remains in the GDB when I examine the file.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Context:&lt;/P&gt;&lt;P&gt;This is a workflow that will be repeated quarterly, maybe monthly. The process is pretty standard: build a network along roadways from fixed points to create a service area. Then buffers are then built off the service area and passed on to a web map and web app.&lt;/P&gt;&lt;P&gt;I could just have someone manually go in after every run to delete the NA layers but would prefer the script clean up after itself.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 15:52:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-a-network-analysis-dataset-via-a/m-p/1049627#M60855</guid>
      <dc:creator>CassKalinski</dc:creator>
      <dc:date>2021-04-21T15:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete a network analysis dataset via a script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-a-network-analysis-dataset-via-a/m-p/1049635#M60856</link>
      <description>&lt;P&gt;Have you tried deleting what may exist from a previous run first at the start of your script?&lt;/P&gt;&lt;P&gt;In other words if it "exists" delete it, then proceed on from there. (move your delete management line to the top)&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 15:56:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-a-network-analysis-dataset-via-a/m-p/1049635#M60856</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-04-21T15:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete a network analysis dataset via a script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-a-network-analysis-dataset-via-a/m-p/1049639#M60857</link>
      <description>&lt;P&gt;Will give that a try...&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 15:58:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-a-network-analysis-dataset-via-a/m-p/1049639#M60857</guid>
      <dc:creator>CassKalinski</dc:creator>
      <dc:date>2021-04-21T15:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete a network analysis dataset via a script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-a-network-analysis-dataset-via-a/m-p/1049732#M60858</link>
      <description>&lt;P&gt;Moving the code I had before to the front did not work, but that lead me to another solution. Running this at the start of the script works...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;dataSets = arcpy.ListDatasets("ServiceArea*", "All")
if dataSets:
    arcpy.AddMessage('Deleting prior datasets...')
    for d in dataSets:
        print(d)
        arcpy.Delete_management(d)
    arcpy.AddMessage('\tPrior service area datasets deleted')
else:
    arcpy.AddMessage('No prior service area datasets found')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Network Analysis names all the datasets 'ServiceArea###', with that last piece being some kind of hash value. Can key off that to build the list to delete. Interestingly, using&amp;nbsp;arcpy.ListDatasets("*", "Network") does not pick up the datasets.&lt;BR /&gt;&lt;BR /&gt;Thank you Dan for the nudge in a working direction!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 18:28:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-a-network-analysis-dataset-via-a/m-p/1049732#M60858</guid>
      <dc:creator>CassKalinski</dc:creator>
      <dc:date>2021-04-21T18:28:48Z</dc:date>
    </item>
  </channel>
</rss>

