ERROR 003207: ...\testLRS\TestEventFC cannot be deleted because it participates in a Location Referencing dataset

397
0
08-10-2022 06:40 PM
GraemeBrowning_Aurizon
Occasional Contributor II

I am trying to use the ArcPy code below with ArcGIS Pro 3.0.0 and a File Geodatabase to:

  1. Create  events for my LRS Network on its first run
  2. Remove my LRS events and then delete its event feature class, before recreating events for my LRS Network on its second and subsequent runs

 

import arcpy
gdb = r"C:\temp\test.gdb"
fdName = "testLRS"
fd = r"{0}\{1}".format(gdb,fdName)
lrsNetworkName = "TestLRSNetworkR"
lrsNetwork = r"{0}\{1}".format(fd,lrsNetworkName)
eventFCname = "TestEventFC"
eventFC = r"{0}\{1}".format(fd,eventFCname)

if arcpy.Exists(eventFC):
    arcpy.AddMessage("Removing LRS Event {0} and deleting {1}".format(eventFCname,eventFC))
    arcpy.locref.RemoveLRSEntity(gdb,"EVENT",eventFCname)
    arcpy.management.Delete(eventFC)
arcpy.AddMessage("Creating LRS Event {0} and its feature class".format(eventFCname))
arcpy.locref.CreateLRSEvent(lrsNetwork,eventFCname,"LINE", "EventId",
                            "FromRouteId", "FromDate", "ToDate", "LocError", "FromMeasure", "ToMeasure",
                            "NO_SPANS_ROUTES", "ToRouteId", "STORE_ROUTE_NAME", "RouteName", "ToRouteName")

 

I run the code by adding it to a toolbox as a Python Script tool with no parameters.

When I run it once the new LRS events are created as expected.

When I re-run it I get an error:

ERROR 003207: ...\testLRS\TestEventFC cannot be deleted because it participates in a Location Referencing dataset

This is unexpected because I have no problem using the Catalog pane to right-click on ..\testLRS\TestEventFC and Delete it.  I am also able to delete it by loading the Delete tool into the Geoprocessing pane - it is just trying to do it from Python that causes the error.

I have tried using a Python sleep function for 30 seconds between RemoveLRSEntity and Delete just in case it needs a little time to finish the RemoveLRSEntity but that makes no difference.

Is there any way that I can use Python code to check for LRS events, remove them as an LRS entity if they exist, and then delete the underlying event feature class?

0 Kudos
0 Replies