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 -------
As blord-castillo says, I tryed to use with block in my edition and the startOperation(),stopOperation() inside this block, but the error occurs in __exit__ Attribute. Folow my actual code:
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 = "Aterar o valor de " + lin[1] + " para " + direcao
escreverArquivoLog(logFile,txtLog)
lin[1] = "yes"
cursor.updateRow(lin)
escreverArquivoLog(logFile,"Suceed!!!")
ed.stopOperation()
The error stil appearing in this code, on exit statement.
arcpy.CheckOutExtension('Network')
row[0]
but I do not see whererow
is ever defined? Is "yes" a valid value for your evaluator for your network dataset (normally it is not)? Try puttingedt.startOperation()
before your cursor block andedt.stopOperation()
after your cursor block. Alternately, try using awith
block for your edit session instead of explicitly starting and stopping (startOperation
andstopOperation
are built into thewith
block).