Error when stop editing a feature in ArcPy

4337
1
10-19-2015 07:21 AM
JoséFilho
New Contributor

I want to make changes in a feature attribute table  that is an edge source of a Network dataset. In the next step, I need to rebuild the Network to make the changes take efect.

The problem is that, when I open the editor session and make changes in attribute table, then when I want to close the session the script crashes.

Here is a sample of my code:

 import arcpy
    from arcpy import env
    arcpy.CheckOutExtension("Network")

    gdb = r"C:\GDB\NetworkGDB.gdb"
    env.workspace = gdb
    env.overwriteOutput = True

    edt = arcpy.da.Editor(gdb)
    edt.startEditing(False,False)
    WHERE = '"OBJECTID_12" = 2'
    direcao = "yes" #This value was set by another process that's indeppend on this one... Inclusive I tried a fixed value like in this example

    with arcpy.da.UpdateCursor("Network_nd_roads",["OBJECTID_12","osm_oneway"],     WHERE) as cursor:
        for lin in cursor:
            txtLog = "Change value from " + lin[1] + " to " + direcao
            escreverArquivoLog(logFile,txtLog) #function to write a logfile
            lin[1] = direcao
            cursor.updateRow(lin)
            escreverArquivoLog(logFile,"Change suceed!!!")

    escreverArquivoLog(logFile,u"Closing edition...")
    edt.stopEditing(True) #-----HERE HAPPENS THE ERROR!!------

The error is:

> *File: C:\SCRIPT\Python\OneWayRules.py*

>

> *Message: RuntimeError: A network source with the specified name don't exist.*

>

> *ArcPy Message: ERROR 999999: Fail to execute function. User don't have permission to execute the operation. [N_1_Desc] An error happens

> when executing (BuildNetwork).*

But as you can see, I dont call *BuildNetwork* function yet, I just make changes in the edige source of my Network.

------ UPDATE -------

    with edt.startEditing() as ed:
        WHERE = '"OBJECTID_12" = 2'
            ed.startOperation ()
            with arcpy.da.UpdateCursor(roadsLayer,["OBJECTID_12","osm_oneway"], WHERE) as cursor:
                for lin in cursor:
                    txtLog = "Change value from " + lin[1] + " to " + direcao
                    escreverArquivoLog(logFile,txtLog)
                    lin[1] = "yes"
                    cursor.updateRow(lin)
                    escreverArquivoLog(logFile,"Suceed!!!")
            ed.stopOperation()
0 Kudos
1 Reply
JoshuaBixby
MVP Esteemed Contributor

I suspect what is happening can be explained in the Build Network documentation:

Build Network

Summary

Reconstructs the network connectivity and attribute information of a network dataset. The network dataset needs to be rebuilt after making edits to the attributes or the features of a participating source feature class. After the source features are edited, the tool establishes the network connectivity only in the areas that have been edited to speed up the build process; however, when the network attributes are edited, the entire extent of the network dataset is rebuilt. This may be a slow operation on a large network dataset.

Usage

Before building a network dataset, an exclusive schema lock is required on the network dataset and the participating source feature classes. This means that you (or anyone else) cannot be editing the participating feature classes. You will receive an error if an exclusive schema lock cannot be obtained.

....

Although you are not directly calling the BuildNetwork function, your error message gives the impression it may be called for you after closing an edit session on a network dataset.  As to why the BuildNetwork function is failing, possibly because it can't gain an exclusive schema lock?

Can you run the Build Network tool successfully outside of trying these edits?

0 Kudos