AnsweredAssumed Answered

Error when stop editing a feature in ArcPy

Question asked by Jose_Filho on Oct 19, 2015
Latest reply on Oct 19, 2015 by bixb0012

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()

Outcomes