I have a table and some fields there(OBJECTID, UN_ID, for example).Table is not empty. how to prevent an edit session from stopping or saving until the field will be filled. I wrote an extension onStopEditing(). It displays a message that the field is empty.

And how to make the module does not complete the editing?

Any suggestions as I am new to this.

import arcpy
import pythonaddins

class Uniq_ID(object):
    def __init__(self):
    def onStopEditing(self, save_changes):
        mxd = arcpy.mapping.MapDocument('current')
        with arcpy.da.SearchCursor(table.name,['OBJECTID','UN_ID'],"UN_ID IS NULL") as cursor:
             for row in cursor:
                 pythonaddins.MessageBox("UN_ID cannot be NULL","Error Message")

        with arcpy.da.SearchCursor(table.name,['OBJECTID','UN_ID'],"len(UN_ID) <>9") as cursor:
             for row in cursor:
                 pythonaddins.MessageBox("UN_ID must have 9 symbols","Error Message")
    del mxd
  • Sounds like a dangerous approach you are taking, you always need an option to stop editing without creating a feature or partially completing an edit. Have you explored beforeStopOperation(self)? – Hornbydd Jul 4 at 14:06
  • @Hornbydd I need the users of database could not save table edits until they fill the field UN_ID . Thank you , I will explore beforeStopOperation. Sorry for my English ) – Lora Jul 4 at 16:25
  • Have you considered modifying the field definition in ArcGIS to set "Allow NULL values" to "No"? – Son of a Beach Jul 4 at 22:13
  • @SonofaBeach I thought about this, my tables are not empty, and ArcGis doesn't allow me to set this option. – Lora Jul 5 at 7:30
  • If the option would suit you, you could create a new field that has the no-NULLs option set (will need a default value) and then copy (calculate) values from your old field. Then delete the old field and rename the new field to what the old field was named. – Son of a Beach Jul 5 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.