7

I am trying to detect when a feature has been copied and pasted. The OnCreateFeature event fires, but I cannot tell if the feature object was copy/pasted. Is there an event or other method to differentiate pasted features from newly created features?

EDIT: Two possible approaches I've thought of, but not sure of efficacy or downsides.

  1. In the OnCreateFeature event, I can read the 'new' feature's attributes, and compare them to the DefaultValue of each field. If every value is default, it's probably a new feature and not a copied feature.
  2. Get the geometry of the 'new' feature, and compare it to the geometry of every selected feature. If there is a match, the feature is a copy/paste.
2
  • 2
    Did you try using ICustomizationFilter to trap when the paste command is invoked ? gis.stackexchange.com/a/8152/59 Commented Nov 9, 2018 at 14:00
  • @KirkKuykendall That's perfect! Post an answer and I'll accept. I'm posting my solution for the sake of posterity.
    – Barbarossa
    Commented Nov 9, 2018 at 16:26

1 Answer 1

3

Going off help provided by Kirk Kuykendall, I came up with the following solution. I wanted to post it here as a c# alternative to this post. It assumes you are already listening for OnStartEditing and OnStopEditing events.

namespace MyAddin {
    public class MyExtensionClass : ESRI.ArcGIS.Desktop.AddIns.Extension {
        private ICustomizationFilter _filter;

        // Constructors and methods to listen for edit events here

        private void OnStartEditing() {
            _filter = new myCustomizationFilter();
            ArcMap.Application.LockCustomization("password", _filter);
        }
        private void OnStopEditing(bool save) {
            ArcMap.Application.UnlockCustomization("password");
        }
    }

    public class myCustomizationFilter : ESRI.ArcGIS.Framework.ICustomizationFilter {
        public bool OnCustomizationEvent(esriCustomizationEvent custEventType, object eventCtx) {
            if (custEventType == esriCustomizationEvent.esriCEInvokeCommand) {
                ICommandItem cmd = eventCtx as ICommandItem;
                if (cmd.Name == "Edit_Paste") {
                    // do something here
                } else if (cmd.Name == "Edit_Copy") {
                    // do something else here
                } else if (cmd.Name == "Edit_Cut") {
                    // do something else here
                }
            }
            return false;
        }
    }
}

All menu, toolbar, and command names and GUIDs can be found here, as well as techniques for finding references to specific command items.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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