I'm creating a tool in ArcGIS Pro 3.0 that will duplicate selected features to a point that is clicked on the map. The process works fine, but does not get added to the undo stack.
For example, I create 3 line features, selected all 3 features, Use my tool (click on map, those 3 features are duplicated with their combined center being on the point that I clicked).
If I were to click 'undo', this undoes my duplicate AND the last line I had created (leaving me as though I'd only created 2 lines).
Solved! Go to Solution.
Chained edit operations are typically used when the results of one call to Execute are needed for a subsequent call. Maybe I'm missing something, but that doesn't seem to be the case here.
Could you try restructuring the code like this:
Create an edit operation
For each feature in the selection set
Create a copy, and call editOp.Create
Call editOp.Execute once at the end
Hi Brett,
Just to confirm- you're using the EditOperation class to duplicate the features, right? Could you send us the EditOperation code that you use in your tool?
Thanks,
--Rich
//edit operation
var edOp = new EditOperation();
//edOp.ExecuteMode = ExecuteModeType.Sequential;
edOp.Name = "Copy Features Tool";
edOp.EditOperationType = EditOperationType.Long;
edOp.SelectModifiedFeatures = false;
edOp.Execute();
//For each feature in selectedFeatures, get the specific OID for that feature
//then, add it to the oIDs list
foreach (var item in allSelectionSetValues.First())
{
var specificValue = item;
var duplicateFeatures = edOp.CreateChainedOperation();
duplicateFeatures.Name = "Duplicate Features";
var gadgetInsp = new Inspector();
gadgetInsp.Load(layer, specificValue);
var geom = gadgetInsp["SHAPE"] as Geometry;
geomList.Add(geom);
var rtoken = duplicateFeatures.Create(gadgetInsp.MapMember, gadgetInsp.ToDictionary(a => a.FieldName, a => a.CurrentValue));
if (duplicateFeatures.Execute())
{
oIDs.Add((long)rtoken.ObjectID);
}
}
Here is the portion of code that has to do with the edit operation after the mouse is clicked.
Check the return value of edOp.Execute(); It might be false. Also check if edOp.IsEmpty is set. But yes I agree with Rich i don't see the need for a chained operation here either.
Chained edit operations are typically used when the results of one call to Execute are needed for a subsequent call. Maybe I'm missing something, but that doesn't seem to be the case here.
Could you try restructuring the code like this:
Create an edit operation
For each feature in the selection set
Create a copy, and call editOp.Create
Call editOp.Execute once at the end
I think I've got it figured. I had to re-arrange the code a bit. After duplicating each selected feature, I was doing a .Move (to clicked location).
//edit operation
var edOp = new EditOperation();
//edOp.ExecuteMode = ExecuteModeType.Sequential;
edOp.Name = "Copy Features Tool";
edOp.EditOperationType = EditOperationType.Long;
edOp.SelectModifiedFeatures = false;
foreach (var item in allSelectionSetValues.First())
{
var specificValue = item;
var gadgetInsp = new Inspector();
gadgetInsp.Load(layer, specificValue);
var geom = gadgetInsp["SHAPE"] as Geometry;
geomList.Add(geom);
var rtoken = edOp.Create(gadgetInsp.MapMember, gadgetInsp.ToDictionary(a => a.FieldName, a => a.CurrentValue));
rowTokens.Add(rtoken);
}
edOp.Execute();