2

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.

closed as unclear what you're asking by PolyGeo Oct 25 '15 at 3:45

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Have you tried checking out the NA license first? arcpy.CheckOutExtension('Network') – crmackey Oct 16 '15 at 14:48
  • Yes, this is checked out – José Roberto Ribeiro Filho Oct 16 '15 at 15:00
  • I think Build Network is called when you close the edit session with a dirty areas in your network. You reference row[0] but I do not see where row is ever defined? Is "yes" a valid value for your evaluator for your network dataset (normally it is not)? Try putting edt.startOperation() before your cursor block and edt.stopOperation() after your cursor block. Alternately, try using a with block for your edit session instead of explicitly starting and stopping (startOperation and stopOperation are built into the with block). – blord-castillo Oct 16 '15 at 19:57
  • Post eddited, the row[0] is a value of the FID I want to edit. The value "yes" is permited and used in other rows in this field. I will try the operation statement and see if it works... – José Roberto Ribeiro Filho Oct 16 '15 at 20:20
  • -----Update---- Still occurring the permission error... but the network sorce error stopped... – José Roberto Ribeiro Filho Oct 16 '15 at 20:35