4 Replies Latest reply on Sep 5, 2014 10:23 AM by Ian Broad

    Trying to edit feature class using arcpy - Field is not editable

    Ian Broad

      We are running ArcGIS Desktop 10.1 SP1 and ArcFM 10.1.276

       

      I have a simple script that inserts a new row with a value into a feature class using the arcpy module.

       

      def sampleArcFM():
          import arcpy
          from arcgisscripting import create
          from win32com.client import Dispatch
          gp = create(10.1)
         
          app = Dispatch('Miner.Framework.Dispatch.MMAppInitializeDispatch')
          au = Dispatch('Miner.Framework.Dispatch.MMAutoupdaterDispatch')
          runtime = Dispatch('Miner.Framework.Dispatch.MMRuntimeEnvironmentDispatch')
         
          from enumerations import mmRuntimeMode,mmLicensedProductCode,mmAutoUpdaterMode
      
          runtime.RuntimeMode = mmRuntimeMode.mmRuntimeModeArcServer
          app.Initialize(mmLicensedProductCode.mmLPArcFM)
          au.AutoUpdaterMode = mmAutoUpdaterMode.mmAUMNoEvents
         
          workspace = "Database Connections\\Test.sde"
          arcpy.env.workspace = workspace
      
          switch = "Database Connections\\Test.sde\\ElectricDataset\\SwitchBank"
      
          edit = arcpy.da.Editor(workspace)
          edit.startEditing(False, True)
          edit.startOperation()
      
          icur = arcpy.da.InsertCursor(switch, ("Comments"))
          icur.insertRow(["Test Comment"])
      
          edit.stopOperation()
          edit.stopEditing(True)
         
          app.Shutdown
          del app, runtime, au
      
      sampleArcFM()
      

       

      When I run the above code on a feature class that (from what I've noticed) participates in the geometric network, I get the following error:

       

      RuntimeError: Field is not editable.

       

      However, when I run the code on a feature class that doesn't participate in the geometric network, the row is inserted correctly.

       

      Also, when I export the data to a file geodatabase with the geometric network intact, I can run the code on a feature class that participates in the geometric network and it works correctly.

       

      Am I missing something here?

       

      Thanks.

        • Re: Trying to edit feature class using arcpy - Field is not editable
          Robert Krisher

          Try not specifying any subfields.  I've had luck with this in the past by creating an inset cursor, calling newrow on the insert cursor, setting a value on the newrow, then inserting the newrow.

          • Re: Trying to edit feature class using arcpy - Field is not editable
            Ian Broad

            Well, I discovered a little more.

             

            I tried what I believe to be Robert Krisher's suggestion, which is to use the standard cursor and not the data access cursor.

             

            So, I used this code instead:

             

            edit = arcpy.da.Editor(workspace)
            edit.startEditing(False, True)
            edit.startOperation()
            
            icur= arcpy.InsertCursor(switch)
            row = icur.newRow()
            row.setValue("Comments", "Test Comment")
            icur.insertRow(row)
            
            edit.stopOperation()
            edit.stopEditing(True)
            
            
            
            
            
            

             

            This did fail with the same message:


            RuntimeError: Field is not editable.

             

            BUT, it also threw a more detailed error than the data access cursor did, which was:

             

            The feature object does not have a valid shape.

             

            So, obviously this means it needs geometry in order to be inserted (if a geometry field exists). This must be a more strict requirement by ArcFM? Because my first script worked fine in the pure ESRI world. This obviously isn't an issue, I just wish the first script threw the same error as this one.

             

            I changed back to the data access cursor and added the Shape field and it inserted correctly.

             

            edit = arcpy.da.Editor(workspace)
            edit.startEditing(False, True)
            edit.startOperation()
            
            icur = arcpy.da.InsertCursor(switch, ("SHAPE@", "Comments"))
            icur.insertRow([(5555, 5555), "Test Comment"])
            
            edit.stopOperation()
            edit.stopEditing(True)
            
            
            
            
            
              • Re: Trying to edit feature class using arcpy - Field is not editable
                Robert Krisher

                I'm suprised that you can do this with the vanilla ESRI features.  I'm pretty sure that at 10.2.1 I can't create a network feature with null geometry, but I would have thought they were enforcing this since 10.x (if not 9.x!).  Either way, you shouldn't be able to create a network feature with null geometry, ArcFM just has the courtesy to throw exceptions when you try and do this =)

                  • Re: Trying to edit feature class using arcpy - Field is not editable
                    Ian Broad

                    Yeah, it totally makes sense that a feature participating in a geometric network should require geometry. It just caused a bit of confusion when it worked in one situation, but not the other. Anyway, what the above told me is that there was a different issue with my conversion script because I was inserting geometry as well as the other field values. It ended up being the Enabled field. I was defaulting to a value of 1 for True, but it didn't like that for some reason. I just removed that field from the cursor and everything worked fine.