ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Desktop.Editing Namespace / EditOperation Class / CreateChainedOperation Method

In This Topic
    CreateChainedOperation Method
    In This Topic
    Creates a follow-on operation which will be shared with this operation on the application's undo stack.
    public EditOperation CreateChainedOperation()
    Public Function CreateChainedOperation() As EditOperation

    Return Value

    A newly created EditOperation that will be merged with this one.
    Call CreateChainedOperation once the parent edit operation is known to have executed successfully.
    Edit Operation Duplicate Features
      var duplicateFeatures = new EditOperation();
      duplicateFeatures.Name = "Duplicate Features";
      //Duplicate with an X and Y offset of 500 map units
      //At 2.x duplicateFeatures.Duplicate(featureLayer, oid, 500.0, 500.0, 0.0);
      //Execute to execute the operation
      //Must be called within QueuedTask.Run
      var insp2 = new Inspector();
      insp2.Load(featureLayer, oid);
      var geom = insp2["SHAPE"] as Geometry;
      var rtoken = duplicateFeatures.Create(insp2.MapMember, insp2.ToDictionary(a => a.FieldName, a => a.CurrentValue));
      if (!duplicateFeatures.IsEmpty)
        if (duplicateFeatures.Execute())//Execute and ExecuteAsync will return true if the operation was successful and false if not
          var modifyOp = duplicateFeatures.CreateChainedOperation();
          modifyOp.Modify(featureLayer, (long)rtoken.ObjectID, GeometryEngine.Instance.Move(geom, 500.0, 500.0));
          if (!modifyOp.IsEmpty)
            var result = modifyOp.Execute();
    Edit Operation Chain Edit Operations
    //Chaining operations is a special case. Use "Chained Operations" when you require multiple transactions 
    //to be undo-able with a single "Undo".
    //The most common use case for operation chaining is creating a feature with an attachement. 
    //Adding an attachment requires the object id (of a new feature) has already been created. 
    var editOperation1 = new EditOperation();
    editOperation1.Name = string.Format("Create point in '{0}'", CurrentTemplate.Layer.Name);
    long newFeatureID = -1;
    //The Create operation has to execute so we can get an object_id
    var token2 = editOperation1.Create(this.CurrentTemplate, polygon);
    //Must be within a QueuedTask
    editOperation1.Execute(); //Note: Execute and ExecuteAsync will return true if the operation was successful and false if not
    if (editOperation1.IsSucceeded)
      newFeatureID = (long)token2.ObjectID;
      //Now, because we have the object id, we can add the attachment.  As we are chaining it, adding the attachment 
      //can be undone as part of the "Undo Create" operation. In other words, only one undo operation will show on the 
      //Pro UI and not two.
      var editOperation2 = editOperation1.CreateChainedOperation();
      //Add the attachement using the new feature id
      editOperation2.AddAttachment(this.CurrentTemplate.Layer, newFeatureID, @"C:\data\images\Hydrant.jpg");
      //Execute the chained edit operation. editOperation1 and editOperation2 show up as a single Undo operation
      //on the UI even though we had two transactions

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also