3

Trying to populate certain attributes as soon as a feature is created. I have tried the python add-in application extension function "onCreateFeature", which does get triggered when a feature is created. The new feature remains selected in the display and table, but then when I execute a "describe" or Search/UpdateCursor within the onCreateFeature class it returns the selection that existed before the feature was digitized. (eg: feature OID 12 is digitized and remains selected/highlighted, but describe and cursor see OID 11 as the current selection.) Any suggestions as to what's wrong here?

class UpdateNewFeature(object):
    """Implementation for listener3cursor_addin.ext3 (Extension)"""
    def __init__(self):
        self.enabled = True
    def onCreateFeature(self):
        TESTline_Lyr     = "TESTlines"
        TESTline_Fields  = ['OBJECTID','NewAttrib','SHAPE_Length'] 

        # count selected features
        d = arcpy.Describe(TESTline_Lyr)
        if len(d.FIDSet) == 0:
            TESTline_Select = 0
        else:
            TESTline_Select = len(d.FIDSet.split(";"))
            print "OID:",FIDSet

        with arcpy.da.UpdateCursor(TESTline_Lyr,TESTline_Fields) as cursor:
            for row in cursor:      
                print "ROW:", row
                # and update a few attributes based on current conditions
  • Perhaps you just need to refresh your display (F5)? – Emil Brundage Jan 20 '15 at 18:25
  • refresh isn't the issue. The most recently digitized feature is highlighted in the display and in the table. The issue is that the UpdateCursor, which is part of the onCreateFeature class, operates on the selection that existed before the current feature was digitized. Perhaps I don't understand what onCreateFature is supposed to do (documentation is absurdly shallow) but I'm assuming it's to allow you to operate on a newly-created feature. – AMurray Jan 21 '15 at 1:13
  • I had the exact same problem. The odd thing was that the script to calculate the attribute of the new feature worked great outside of the extension, i.e. selecting the new feature and running as a stand alone script. So eventually I just removed the code from the extension script and called the stand alone script so that a dialog box pops up and the user has to run it to get the attributes calculated. I agree that the documentation is useless, so would like to hear if you find a better solution. – Nadine Dec 19 '16 at 13:41
  • Nadine, not sure I fully understand, but it sounds like, after digitizing a feature, your user still has to do an extra step to update its attributes. If so, I can post another "answer" here with the snippet I'm using to update as soon as user "finishes sketch". – AMurray Dec 20 '16 at 15:15
3

In case anyone else comes looking for an answer....

Revisited this, and by persistence or dumb luck (no thanks to any documentation), I found something that works. When digitizing a new feature and finish the sketch, these events are triggered in this order:

onStartOperation

onCreateFeature

beforeStopOperation

onStopOperation

onEditorSelectionChanged

I was naively using onCreateFeature (entire ESRI documentation: "Occurs whenever a new feature is created.") But onCreateFeature is triggered before the edit operation is complete, which makes sense now in the context of this list. Of course, other events besides digitizing will trigger onEditorSelectionChanged, but when I run the UpdateCursor on the currently selected feature(s), I only update attributes when the selection is a single feature and where key attribs are null.

(Context: Python addin; editing a versioned geodatabase without option to "move edits to base")

0

I think you're going to need to save edits first

When you make edits to a table/feature class in ArcGIS, those edits are held in memory and are not committed to the actual table/feature class until you save edits. This is why you can "undo" edits when you are in an editing session. So, if one tries to execute a cursor against a dataset prior to committing those edits by saving them, the cursor is not likely to find those edits as its looking at the table prior to editing. The appearance of those edits within the table as you are editing it is just a representation of what you will commit when you save edits

  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – SS_Rebelious Jan 25 '15 at 23:12
  • @SS_Rebelious: Actually, it could. When you make edits to a table/feature class in ArcGIS, those edits are held in memory and are not committed to the actual table/feature class until you save edits. This is why you can "undo" edits when you are in an editing session. So, if one tries to execute a cursor against a dataset prior to committing those edits by saving them, the cursor is not likely to find those edits as its looking at the table prior to editing. The appearance of those edits within the table as you are editing it is just a representation of what you will commit when you save edits – MrBubbles Jan 26 '15 at 0:10
  • Would you be able to use the content of your comment to expand upon your answer that the system has flagged as being of low quality due to its brevity, please? I recommend always treating "about a paragraph" being a minimum length answer (or question). – PolyGeo Jan 26 '15 at 0:23
  • Well thanks folks. It sounds as if I'm going to have to save manually, which will clear my selection (the new feature), and therefore have to select it again by attribute (OID) or by location before I can update the attributes. Not a very efficient workflow unfortunately. Makes me wonder how you could use an onCreateFeature function. But will have to do some experimenting.... – AMurray Jan 27 '15 at 4:22

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.