<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic First Edit Operation Fails in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-edit-operation-fails/m-p/1511386#M11913</link>
    <description>&lt;P&gt;Hi Community,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have created an Add-in - In which whenever the button is active, when you create a polyline(Plan_Kabler) point features are placed along the line alongside with polygons. These are directional according to the polyline segments. Points are referred to as muffePunktLayer and the polygons are referred to as muffeArealLayer.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;When the polyline is edited or deleted, it deletes the original placements, and places new ones along the line if its edited, and none if its been deleted.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;No matter how much I try - I cannot figure out why the first operation of edit always fails.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;i.e: I place the polyline, and given either muffePunktLayer or muffeArealLayer is placed before the other, that first feature that is being placed, fails, but the remaining of the features succeed to get placed.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Similarly when it either gets deleted or edited, the first feature to be deleted fails to be deleted, but then in return the first feature to be placed succeeds, unlike when the polyline is first inserted.&amp;nbsp; I am really at a loss to what the mistake could be, and would need some assistance.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Button1.cs. below;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;P&gt;using ArcGIS.Core.CIM;&lt;BR /&gt;using ArcGIS.Core.Data;&lt;BR /&gt;using ArcGIS.Core.Events;&lt;BR /&gt;using ArcGIS.Core.Geometry;&lt;BR /&gt;using ArcGIS.Core.Internal.Geometry;&lt;BR /&gt;using ArcGIS.Desktop.Editing;&lt;BR /&gt;using ArcGIS.Desktop.Editing.Events;&lt;BR /&gt;using ArcGIS.Desktop.Framework.Contracts;&lt;BR /&gt;using ArcGIS.Desktop.Framework.Threading.Tasks;&lt;BR /&gt;using ArcGIS.Desktop.Mapping;&lt;BR /&gt;using System;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.Linq;&lt;BR /&gt;using System.Threading.Tasks;&lt;/P&gt;&lt;P&gt;namespace muffe_add_in&lt;BR /&gt;{&lt;BR /&gt;internal class Button1 : Button&lt;BR /&gt;{&lt;BR /&gt;private SubscriptionToken _rowCreatedEventToken;&lt;BR /&gt;private SubscriptionToken _rowChangedEventToken;&lt;BR /&gt;private SubscriptionToken _rowDeletedEventToken; // New token for RowDeletedEvent&lt;BR /&gt;private bool _isActive = false; // Field to track the active state&lt;BR /&gt;private Dictionary&amp;lt;long, Geometry&amp;gt; _originalGeometries = new Dictionary&amp;lt;long, Geometry&amp;gt;();&lt;/P&gt;&lt;P&gt;protected override void OnClick()&lt;BR /&gt;{&lt;BR /&gt;_isActive = !_isActive; // Toggle the active state&lt;/P&gt;&lt;P&gt;if (_isActive)&lt;BR /&gt;{&lt;BR /&gt;// Ensure the subscription logic is awaited properly&lt;BR /&gt;QueuedTask.Run(async () =&amp;gt;&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;// Assuming you have a way to access or select the feature layer you're working with&lt;BR /&gt;var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault(l =&amp;gt; l.Name == "Plan Kabler");&lt;BR /&gt;if (featureLayer != null)&lt;BR /&gt;{&lt;BR /&gt;// Correctly obtain the spatial reference from the feature layer's dataset&lt;BR /&gt;var spatialReference = await QueuedTask.Run(() =&amp;gt; featureLayer.GetFeatureClass().GetDefinition().GetSpatialReference());&lt;/P&gt;&lt;P&gt;_rowCreatedEventToken = RowCreatedEvent.Subscribe((args) =&amp;gt; OnRowCreatedOrEdited(args, true), featureLayer.GetTable(), false);&lt;BR /&gt;_rowChangedEventToken = RowChangedEvent.Subscribe((args) =&amp;gt; OnRowCreatedOrEdited(args, false), featureLayer.GetTable(), false);&lt;BR /&gt;_rowDeletedEventToken = RowDeletedEvent.Subscribe(OnRowDeleted, featureLayer.GetTable(), false); // Subscribe to RowDeletedEvent&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;// Log the exception to the ArcGIS Pro log or show a message box&lt;BR /&gt;System.Diagnostics.Debug.WriteLine($"Error subscribing to events: {ex.Message}");&lt;BR /&gt;}&lt;BR /&gt;}).Wait();&lt;BR /&gt;UpdateCaption("Deactivate Muffe");&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;// Unsubscribe logic should also be within QueuedTask.Run if it interacts with ArcGIS objects&lt;BR /&gt;QueuedTask.Run(() =&amp;gt;&lt;BR /&gt;{&lt;BR /&gt;RowCreatedEvent.Unsubscribe(_rowCreatedEventToken);&lt;BR /&gt;RowChangedEvent.Unsubscribe(_rowChangedEventToken);&lt;BR /&gt;RowDeletedEvent.Unsubscribe(_rowDeletedEventToken); // Unsubscribe from RowDeletedEvent&lt;BR /&gt;_rowCreatedEventToken = null;&lt;BR /&gt;_rowChangedEventToken = null;&lt;BR /&gt;_rowDeletedEventToken = null;&lt;BR /&gt;}).Wait();&lt;BR /&gt;UpdateCaption("Activate Muffe");&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private void UpdateCaption(string newCaption)&lt;BR /&gt;{&lt;BR /&gt;// Directly update the caption since this method is called within QueuedTask.Run&lt;BR /&gt;this.Caption = newCaption;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private async void OnRowCreatedOrEdited(RowChangedEventArgs args, bool isInsert)&lt;BR /&gt;{&lt;BR /&gt;if (!_isActive) return; // Check if the script is active before proceeding&lt;BR /&gt;if (!(args.Row is Feature feature)) return;&lt;BR /&gt;if (feature.GetTable().GetName() != "Plan_Kabler") return;&lt;/P&gt;&lt;P&gt;var featureId = feature.GetObjectID();&lt;BR /&gt;var polyline = feature.GetShape() as Polyline;&lt;BR /&gt;if (polyline == null) return;&lt;/P&gt;&lt;P&gt;// If there is an existing geometry, delete it&lt;BR /&gt;if (_originalGeometries.ContainsKey(featureId))&lt;BR /&gt;{&lt;BR /&gt;await QueuedTask.Run(async () =&amp;gt;&lt;BR /&gt;{&lt;BR /&gt;var muffePunktLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault(l =&amp;gt; l.Name == "Muffe Punkt");&lt;BR /&gt;var muffeArealLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault(l =&amp;gt; l.Name == "Muffe Areal");&lt;BR /&gt;if (muffePunktLayer == null || muffeArealLayer == null) return;&lt;/P&gt;&lt;P&gt;// Delete intersecting templates&lt;BR /&gt;await DeleteIntersectingTemplates(featureId, muffePunktLayer, muffeArealLayer);&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;// Remove the old geometry from the dictionary&lt;BR /&gt;_originalGeometries.Remove(featureId);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Store the new geometry&lt;BR /&gt;_originalGeometries[featureId] = polyline.Clone();&lt;/P&gt;&lt;P&gt;await QueuedTask.Run(async () =&amp;gt;&lt;BR /&gt;{&lt;BR /&gt;var muffePunktLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault(l =&amp;gt; l.Name == "Muffe Punkt");&lt;BR /&gt;var muffeArealLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault(l =&amp;gt; l.Name == "Muffe Areal");&lt;BR /&gt;if (muffePunktLayer == null || muffeArealLayer == null) return;&lt;/P&gt;&lt;P&gt;if (isInsert)&lt;BR /&gt;{&lt;BR /&gt;// Logic for handling row insertions&lt;BR /&gt;await ApplyTemplateAlongPolyline(polyline, muffePunktLayer, muffeArealLayer);&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;// Logic for handling row updates&lt;BR /&gt;await ApplyTemplateAlongPolyline(polyline, muffePunktLayer, muffeArealLayer);&lt;BR /&gt;}&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private async void OnRowDeleted(RowChangedEventArgs args)&lt;BR /&gt;{&lt;BR /&gt;if (!_isActive) return; // Check if the script is active before proceeding&lt;BR /&gt;if (!(args.Row is Feature feature)) return;&lt;BR /&gt;if (feature.GetTable().GetName() != "Plan_Kabler") return;&lt;/P&gt;&lt;P&gt;var featureId = feature.GetObjectID();&lt;/P&gt;&lt;P&gt;await QueuedTask.Run(async () =&amp;gt;&lt;BR /&gt;{&lt;BR /&gt;var muffePunktLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault(l =&amp;gt; l.Name == "Muffe Punkt");&lt;BR /&gt;var muffeArealLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault(l =&amp;gt; l.Name == "Muffe Areal");&lt;BR /&gt;if (muffePunktLayer == null || muffeArealLayer == null) return;&lt;/P&gt;&lt;P&gt;// Logic for handling row deletions&lt;BR /&gt;await DeleteIntersectingTemplates(featureId, muffePunktLayer, muffeArealLayer);&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private async Task ApplyTemplateAlongPolyline(Polyline polyline, FeatureLayer muffePunktLayer, FeatureLayer muffeArealLayer)&lt;BR /&gt;{&lt;BR /&gt;// Ensure spatial reference is correctly obtained&lt;BR /&gt;var spatialReference = await QueuedTask.Run(() =&amp;gt; muffeArealLayer.GetFeatureClass().GetDefinition().GetSpatialReference());&lt;/P&gt;&lt;P&gt;double interval = 100.0; // Interval in meters&lt;BR /&gt;double distanceToNextPoint = 0; // Start with 0 to place the first point immediately&lt;/P&gt;&lt;P&gt;foreach (var part in polyline.Parts)&lt;BR /&gt;{&lt;BR /&gt;double distanceCoveredInSegment = 0.0;&lt;BR /&gt;foreach (var segment in part)&lt;BR /&gt;{&lt;BR /&gt;double segmentLength = CalculateSegmentLength(segment);&lt;/P&gt;&lt;P&gt;while (distanceCoveredInSegment + distanceToNextPoint &amp;lt;= segmentLength)&lt;BR /&gt;{&lt;BR /&gt;double proportion = distanceToNextPoint / segmentLength;&lt;BR /&gt;MapPoint position = CalculatePositionAlongSegment(segment, proportion + (distanceCoveredInSegment / segmentLength));&lt;BR /&gt;double angle = CalculateSegmentAngle(segment);&lt;/P&gt;&lt;P&gt;try&lt;BR /&gt;{&lt;BR /&gt;// Attempt to create and place the point and polygons at this position&lt;BR /&gt;await CreateAndPlacePolygons(position, angle, spatialReference, muffeArealLayer);&lt;BR /&gt;await CreateFeatureInLayer(muffePunktLayer, position);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;// Log or handle the error&lt;BR /&gt;Console.WriteLine($"Failed to create feature: {ex.Message}");&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;distanceCoveredInSegment += distanceToNextPoint;&lt;BR /&gt;distanceToNextPoint = interval; // Reset after placing a point&lt;BR /&gt;}&lt;BR /&gt;distanceToNextPoint -= (segmentLength - distanceCoveredInSegment);&lt;BR /&gt;distanceCoveredInSegment = 0.0;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private double CalculateSegmentLength(Segment segment)&lt;BR /&gt;{&lt;BR /&gt;return Math.Sqrt(Math.Pow(segment.EndPoint.X - segment.StartPoint.X, 2) + Math.Pow(segment.EndPoint.Y - segment.StartPoint.Y, 2));&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private MapPoint CalculatePositionAlongSegment(Segment segment, double proportion)&lt;BR /&gt;{&lt;BR /&gt;double x = segment.StartPoint.X + (segment.EndPoint.X - segment.StartPoint.X) * proportion;&lt;BR /&gt;double y = segment.StartPoint.Y + (segment.EndPoint.Y - segment.StartPoint.Y) * proportion;&lt;BR /&gt;return MapPointBuilder.CreateMapPoint(x, y, segment.SpatialReference);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private double CalculateSegmentAngle(Segment segment)&lt;BR /&gt;{&lt;BR /&gt;double dx = segment.EndPoint.X - segment.StartPoint.X;&lt;BR /&gt;double dy = segment.EndPoint.Y - segment.StartPoint.Y;&lt;BR /&gt;return Math.Atan2(dy, dx) * (180 / Math.PI); // Angle in degrees&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private async Task CreateAndPlacePolygons(MapPoint position, double angle, SpatialReference spatialReference, FeatureLayer layer)&lt;BR /&gt;{&lt;BR /&gt;// Adjust the offset distances for left and right polygons&lt;BR /&gt;double offsetDistanceLeft = 5; // Offset distance for left polygons&lt;BR /&gt;double offsetDistanceRight = 10; // Offset distance for right polygons&lt;/P&gt;&lt;P&gt;// Calculate perpendicular direction for left and right offsets&lt;BR /&gt;double angleLeft = angle - 90; // Perpendicular to the left&lt;BR /&gt;double angleRight = angle + 90; // Perpendicular to the right&lt;/P&gt;&lt;P&gt;// Create offset points for left and right polygons using the perpendicular angles&lt;BR /&gt;MapPoint offsetPointLeft = RotateAndMovePoint(position, angleLeft, offsetDistanceLeft, spatialReference);&lt;BR /&gt;MapPoint offsetPointRight = RotateAndMovePoint(position, angleRight, offsetDistanceRight, spatialReference);&lt;/P&gt;&lt;P&gt;// Create polygons based on the direction of the segment&lt;BR /&gt;Polygon orientedPolygonLeft = CreateOrientedPolygon(offsetPointLeft, angle, spatialReference);&lt;BR /&gt;await CreateFeatureInLayer(layer, orientedPolygonLeft);&lt;/P&gt;&lt;P&gt;Polygon orientedPolygonRight = CreateOrientedPolygon(offsetPointRight, angle, spatialReference);&lt;BR /&gt;await CreateFeatureInLayer(layer, orientedPolygonRight);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private MapPoint RotateAndMovePoint(MapPoint point, double angleDegrees, double distance, SpatialReference spatialReference)&lt;BR /&gt;{&lt;BR /&gt;double angleRadians = angleDegrees * (Math.PI / 180);&lt;/P&gt;&lt;P&gt;double offsetX = Math.Cos(angleRadians) * distance;&lt;BR /&gt;double offsetY = Math.Sin(angleRadians) * distance;&lt;/P&gt;&lt;P&gt;return MapPointBuilder.CreateMapPoint(point.X + offsetX, point.Y + offsetY, spatialReference);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private async Task CreateFeatureInLayer(FeatureLayer layer, Geometry geometry)&lt;BR /&gt;{&lt;BR /&gt;var editOperation = new EditOperation&lt;BR /&gt;{&lt;BR /&gt;Name = $"Create feature in {layer.Name}"&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;editOperation.Create(layer, geometry);&lt;/P&gt;&lt;P&gt;var result = await editOperation.ExecuteAsync();&lt;BR /&gt;if (!result) // If the result is false, the operation failed&lt;BR /&gt;{&lt;BR /&gt;var errorMessage = editOperation.ErrorMessage;&lt;BR /&gt;// Log the errorMessage or display it to understand why the operation failed&lt;BR /&gt;System.Diagnostics.Debug.WriteLine($"Error creating feature in {layer.Name}: {errorMessage}");&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private Polygon CreateOrientedPolygon(MapPoint centerPoint, double angle, SpatialReference spatialReference)&lt;BR /&gt;{&lt;BR /&gt;double width = 10; // Width of the rectangle&lt;BR /&gt;double height = 5; // Height of the rectangle&lt;/P&gt;&lt;P&gt;double halfWidth = width / 2;&lt;BR /&gt;double halfHeight = height / 2;&lt;/P&gt;&lt;P&gt;// Use MapPointBuilder to create points with a spatial reference&lt;BR /&gt;MapPoint[] cornerPoints = new MapPoint[]&lt;BR /&gt;{&lt;BR /&gt;MapPointBuilder.CreateMapPoint(centerPoint.X - halfWidth, centerPoint.Y - halfHeight, spatialReference),&lt;BR /&gt;MapPointBuilder.CreateMapPoint(centerPoint.X + halfWidth, centerPoint.Y - halfHeight, spatialReference),&lt;BR /&gt;MapPointBuilder.CreateMapPoint(centerPoint.X + halfWidth, centerPoint.Y + halfHeight, spatialReference),&lt;BR /&gt;MapPointBuilder.CreateMapPoint(centerPoint.X - halfWidth, centerPoint.Y + halfHeight, spatialReference)&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;MapPoint[] rotatedPoints = cornerPoints.Select(point =&amp;gt; RotatePoint(point, centerPoint, angle, spatialReference)).ToArray();&lt;/P&gt;&lt;P&gt;Polygon orientedPolygon = new PolygonBuilder(rotatedPoints.Select(p =&amp;gt; new Coordinate2D(p.X, p.Y)), spatialReference).ToGeometry();&lt;/P&gt;&lt;P&gt;return orientedPolygon;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private MapPoint RotatePoint(MapPoint point, MapPoint pivot, double angleDegrees, SpatialReference spatialReference)&lt;BR /&gt;{&lt;BR /&gt;double angleRadians = angleDegrees * (Math.PI / 180);&lt;/P&gt;&lt;P&gt;double cosTheta = Math.Cos(angleRadians);&lt;BR /&gt;double sinTheta = Math.Sin(angleRadians);&lt;/P&gt;&lt;P&gt;double translatedX = point.X - pivot.X;&lt;BR /&gt;double translatedY = point.Y - pivot.Y;&lt;/P&gt;&lt;P&gt;double rotatedX = translatedX * cosTheta - translatedY * sinTheta;&lt;BR /&gt;double rotatedY = translatedX * sinTheta + translatedY * cosTheta;&lt;/P&gt;&lt;P&gt;return MapPointBuilder.CreateMapPoint(rotatedX + pivot.X, rotatedY + pivot.Y, spatialReference);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private async Task DeleteIntersectingTemplates(long featureId, FeatureLayer muffePunktLayer, FeatureLayer muffeArealLayer)&lt;BR /&gt;{&lt;BR /&gt;if (!_originalGeometries.TryGetValue(featureId, out var originalGeometry))&lt;BR /&gt;{&lt;BR /&gt;return; // If not found, exit the method&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;var bufferedGeometry = GeometryEngine.Instance.Buffer(originalGeometry, 10);&lt;/P&gt;&lt;P&gt;// Use different spatial queries based on the layer type&lt;BR /&gt;await DeleteFeaturesBasedOnLayerType(muffePunktLayer, bufferedGeometry);&lt;BR /&gt;await DeleteFeaturesBasedOnLayerType(muffeArealLayer, bufferedGeometry);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private async Task DeleteFeaturesBasedOnLayerType(FeatureLayer layer, Geometry bufferedGeometry)&lt;BR /&gt;{&lt;BR /&gt;SpatialQueryFilter spatialQueryFilter = new SpatialQueryFilter&lt;BR /&gt;{&lt;BR /&gt;FilterGeometry = bufferedGeometry,&lt;BR /&gt;SpatialRelationship = SpatialRelationship.Intersects&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;List&amp;lt;Geometry&amp;gt; deletedGeometries = new List&amp;lt;Geometry&amp;gt;();&lt;BR /&gt;var featureTable = layer.GetTable();&lt;BR /&gt;if (featureTable == null) return;&lt;/P&gt;&lt;P&gt;using (var cursor = featureTable.Search(spatialQueryFilter, false))&lt;BR /&gt;{&lt;BR /&gt;while (cursor.MoveNext())&lt;BR /&gt;{&lt;BR /&gt;var feature = cursor.Current as Feature;&lt;BR /&gt;deletedGeometries.Add(feature.GetShape().Clone());&lt;/P&gt;&lt;P&gt;// Create a separate EditOperation for each feature&lt;BR /&gt;var editOperation = new EditOperation&lt;BR /&gt;{&lt;BR /&gt;Name = $"Delete feature in {layer.Name}"&lt;BR /&gt;};&lt;BR /&gt;editOperation.Delete(feature);&lt;/P&gt;&lt;P&gt;bool result = await editOperation.ExecuteAsync();&lt;BR /&gt;if (!result)&lt;BR /&gt;{&lt;BR /&gt;System.Diagnostics.Debug.WriteLine($"Failed to delete intersecting feature in {layer.Name}");&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;/LI-SPOILER&gt;&lt;P&gt;Kind regards,&amp;nbsp;&lt;BR /&gt;Marco&lt;/P&gt;</description>
    <pubDate>Mon, 29 Jul 2024 06:50:34 GMT</pubDate>
    <dc:creator>GobiGobletsson</dc:creator>
    <dc:date>2024-07-29T06:50:34Z</dc:date>
    <item>
      <title>First Edit Operation Fails</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-edit-operation-fails/m-p/1511386#M11913</link>
      <description>&lt;P&gt;Hi Community,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have created an Add-in - In which whenever the button is active, when you create a polyline(Plan_Kabler) point features are placed along the line alongside with polygons. These are directional according to the polyline segments. Points are referred to as muffePunktLayer and the polygons are referred to as muffeArealLayer.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;When the polyline is edited or deleted, it deletes the original placements, and places new ones along the line if its edited, and none if its been deleted.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;No matter how much I try - I cannot figure out why the first operation of edit always fails.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;i.e: I place the polyline, and given either muffePunktLayer or muffeArealLayer is placed before the other, that first feature that is being placed, fails, but the remaining of the features succeed to get placed.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Similarly when it either gets deleted or edited, the first feature to be deleted fails to be deleted, but then in return the first feature to be placed succeeds, unlike when the polyline is first inserted.&amp;nbsp; I am really at a loss to what the mistake could be, and would need some assistance.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Button1.cs. below;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;P&gt;using ArcGIS.Core.CIM;&lt;BR /&gt;using ArcGIS.Core.Data;&lt;BR /&gt;using ArcGIS.Core.Events;&lt;BR /&gt;using ArcGIS.Core.Geometry;&lt;BR /&gt;using ArcGIS.Core.Internal.Geometry;&lt;BR /&gt;using ArcGIS.Desktop.Editing;&lt;BR /&gt;using ArcGIS.Desktop.Editing.Events;&lt;BR /&gt;using ArcGIS.Desktop.Framework.Contracts;&lt;BR /&gt;using ArcGIS.Desktop.Framework.Threading.Tasks;&lt;BR /&gt;using ArcGIS.Desktop.Mapping;&lt;BR /&gt;using System;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.Linq;&lt;BR /&gt;using System.Threading.Tasks;&lt;/P&gt;&lt;P&gt;namespace muffe_add_in&lt;BR /&gt;{&lt;BR /&gt;internal class Button1 : Button&lt;BR /&gt;{&lt;BR /&gt;private SubscriptionToken _rowCreatedEventToken;&lt;BR /&gt;private SubscriptionToken _rowChangedEventToken;&lt;BR /&gt;private SubscriptionToken _rowDeletedEventToken; // New token for RowDeletedEvent&lt;BR /&gt;private bool _isActive = false; // Field to track the active state&lt;BR /&gt;private Dictionary&amp;lt;long, Geometry&amp;gt; _originalGeometries = new Dictionary&amp;lt;long, Geometry&amp;gt;();&lt;/P&gt;&lt;P&gt;protected override void OnClick()&lt;BR /&gt;{&lt;BR /&gt;_isActive = !_isActive; // Toggle the active state&lt;/P&gt;&lt;P&gt;if (_isActive)&lt;BR /&gt;{&lt;BR /&gt;// Ensure the subscription logic is awaited properly&lt;BR /&gt;QueuedTask.Run(async () =&amp;gt;&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;// Assuming you have a way to access or select the feature layer you're working with&lt;BR /&gt;var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault(l =&amp;gt; l.Name == "Plan Kabler");&lt;BR /&gt;if (featureLayer != null)&lt;BR /&gt;{&lt;BR /&gt;// Correctly obtain the spatial reference from the feature layer's dataset&lt;BR /&gt;var spatialReference = await QueuedTask.Run(() =&amp;gt; featureLayer.GetFeatureClass().GetDefinition().GetSpatialReference());&lt;/P&gt;&lt;P&gt;_rowCreatedEventToken = RowCreatedEvent.Subscribe((args) =&amp;gt; OnRowCreatedOrEdited(args, true), featureLayer.GetTable(), false);&lt;BR /&gt;_rowChangedEventToken = RowChangedEvent.Subscribe((args) =&amp;gt; OnRowCreatedOrEdited(args, false), featureLayer.GetTable(), false);&lt;BR /&gt;_rowDeletedEventToken = RowDeletedEvent.Subscribe(OnRowDeleted, featureLayer.GetTable(), false); // Subscribe to RowDeletedEvent&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;// Log the exception to the ArcGIS Pro log or show a message box&lt;BR /&gt;System.Diagnostics.Debug.WriteLine($"Error subscribing to events: {ex.Message}");&lt;BR /&gt;}&lt;BR /&gt;}).Wait();&lt;BR /&gt;UpdateCaption("Deactivate Muffe");&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;// Unsubscribe logic should also be within QueuedTask.Run if it interacts with ArcGIS objects&lt;BR /&gt;QueuedTask.Run(() =&amp;gt;&lt;BR /&gt;{&lt;BR /&gt;RowCreatedEvent.Unsubscribe(_rowCreatedEventToken);&lt;BR /&gt;RowChangedEvent.Unsubscribe(_rowChangedEventToken);&lt;BR /&gt;RowDeletedEvent.Unsubscribe(_rowDeletedEventToken); // Unsubscribe from RowDeletedEvent&lt;BR /&gt;_rowCreatedEventToken = null;&lt;BR /&gt;_rowChangedEventToken = null;&lt;BR /&gt;_rowDeletedEventToken = null;&lt;BR /&gt;}).Wait();&lt;BR /&gt;UpdateCaption("Activate Muffe");&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private void UpdateCaption(string newCaption)&lt;BR /&gt;{&lt;BR /&gt;// Directly update the caption since this method is called within QueuedTask.Run&lt;BR /&gt;this.Caption = newCaption;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private async void OnRowCreatedOrEdited(RowChangedEventArgs args, bool isInsert)&lt;BR /&gt;{&lt;BR /&gt;if (!_isActive) return; // Check if the script is active before proceeding&lt;BR /&gt;if (!(args.Row is Feature feature)) return;&lt;BR /&gt;if (feature.GetTable().GetName() != "Plan_Kabler") return;&lt;/P&gt;&lt;P&gt;var featureId = feature.GetObjectID();&lt;BR /&gt;var polyline = feature.GetShape() as Polyline;&lt;BR /&gt;if (polyline == null) return;&lt;/P&gt;&lt;P&gt;// If there is an existing geometry, delete it&lt;BR /&gt;if (_originalGeometries.ContainsKey(featureId))&lt;BR /&gt;{&lt;BR /&gt;await QueuedTask.Run(async () =&amp;gt;&lt;BR /&gt;{&lt;BR /&gt;var muffePunktLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault(l =&amp;gt; l.Name == "Muffe Punkt");&lt;BR /&gt;var muffeArealLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault(l =&amp;gt; l.Name == "Muffe Areal");&lt;BR /&gt;if (muffePunktLayer == null || muffeArealLayer == null) return;&lt;/P&gt;&lt;P&gt;// Delete intersecting templates&lt;BR /&gt;await DeleteIntersectingTemplates(featureId, muffePunktLayer, muffeArealLayer);&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;// Remove the old geometry from the dictionary&lt;BR /&gt;_originalGeometries.Remove(featureId);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Store the new geometry&lt;BR /&gt;_originalGeometries[featureId] = polyline.Clone();&lt;/P&gt;&lt;P&gt;await QueuedTask.Run(async () =&amp;gt;&lt;BR /&gt;{&lt;BR /&gt;var muffePunktLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault(l =&amp;gt; l.Name == "Muffe Punkt");&lt;BR /&gt;var muffeArealLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault(l =&amp;gt; l.Name == "Muffe Areal");&lt;BR /&gt;if (muffePunktLayer == null || muffeArealLayer == null) return;&lt;/P&gt;&lt;P&gt;if (isInsert)&lt;BR /&gt;{&lt;BR /&gt;// Logic for handling row insertions&lt;BR /&gt;await ApplyTemplateAlongPolyline(polyline, muffePunktLayer, muffeArealLayer);&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;// Logic for handling row updates&lt;BR /&gt;await ApplyTemplateAlongPolyline(polyline, muffePunktLayer, muffeArealLayer);&lt;BR /&gt;}&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private async void OnRowDeleted(RowChangedEventArgs args)&lt;BR /&gt;{&lt;BR /&gt;if (!_isActive) return; // Check if the script is active before proceeding&lt;BR /&gt;if (!(args.Row is Feature feature)) return;&lt;BR /&gt;if (feature.GetTable().GetName() != "Plan_Kabler") return;&lt;/P&gt;&lt;P&gt;var featureId = feature.GetObjectID();&lt;/P&gt;&lt;P&gt;await QueuedTask.Run(async () =&amp;gt;&lt;BR /&gt;{&lt;BR /&gt;var muffePunktLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault(l =&amp;gt; l.Name == "Muffe Punkt");&lt;BR /&gt;var muffeArealLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault(l =&amp;gt; l.Name == "Muffe Areal");&lt;BR /&gt;if (muffePunktLayer == null || muffeArealLayer == null) return;&lt;/P&gt;&lt;P&gt;// Logic for handling row deletions&lt;BR /&gt;await DeleteIntersectingTemplates(featureId, muffePunktLayer, muffeArealLayer);&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private async Task ApplyTemplateAlongPolyline(Polyline polyline, FeatureLayer muffePunktLayer, FeatureLayer muffeArealLayer)&lt;BR /&gt;{&lt;BR /&gt;// Ensure spatial reference is correctly obtained&lt;BR /&gt;var spatialReference = await QueuedTask.Run(() =&amp;gt; muffeArealLayer.GetFeatureClass().GetDefinition().GetSpatialReference());&lt;/P&gt;&lt;P&gt;double interval = 100.0; // Interval in meters&lt;BR /&gt;double distanceToNextPoint = 0; // Start with 0 to place the first point immediately&lt;/P&gt;&lt;P&gt;foreach (var part in polyline.Parts)&lt;BR /&gt;{&lt;BR /&gt;double distanceCoveredInSegment = 0.0;&lt;BR /&gt;foreach (var segment in part)&lt;BR /&gt;{&lt;BR /&gt;double segmentLength = CalculateSegmentLength(segment);&lt;/P&gt;&lt;P&gt;while (distanceCoveredInSegment + distanceToNextPoint &amp;lt;= segmentLength)&lt;BR /&gt;{&lt;BR /&gt;double proportion = distanceToNextPoint / segmentLength;&lt;BR /&gt;MapPoint position = CalculatePositionAlongSegment(segment, proportion + (distanceCoveredInSegment / segmentLength));&lt;BR /&gt;double angle = CalculateSegmentAngle(segment);&lt;/P&gt;&lt;P&gt;try&lt;BR /&gt;{&lt;BR /&gt;// Attempt to create and place the point and polygons at this position&lt;BR /&gt;await CreateAndPlacePolygons(position, angle, spatialReference, muffeArealLayer);&lt;BR /&gt;await CreateFeatureInLayer(muffePunktLayer, position);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;// Log or handle the error&lt;BR /&gt;Console.WriteLine($"Failed to create feature: {ex.Message}");&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;distanceCoveredInSegment += distanceToNextPoint;&lt;BR /&gt;distanceToNextPoint = interval; // Reset after placing a point&lt;BR /&gt;}&lt;BR /&gt;distanceToNextPoint -= (segmentLength - distanceCoveredInSegment);&lt;BR /&gt;distanceCoveredInSegment = 0.0;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private double CalculateSegmentLength(Segment segment)&lt;BR /&gt;{&lt;BR /&gt;return Math.Sqrt(Math.Pow(segment.EndPoint.X - segment.StartPoint.X, 2) + Math.Pow(segment.EndPoint.Y - segment.StartPoint.Y, 2));&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private MapPoint CalculatePositionAlongSegment(Segment segment, double proportion)&lt;BR /&gt;{&lt;BR /&gt;double x = segment.StartPoint.X + (segment.EndPoint.X - segment.StartPoint.X) * proportion;&lt;BR /&gt;double y = segment.StartPoint.Y + (segment.EndPoint.Y - segment.StartPoint.Y) * proportion;&lt;BR /&gt;return MapPointBuilder.CreateMapPoint(x, y, segment.SpatialReference);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private double CalculateSegmentAngle(Segment segment)&lt;BR /&gt;{&lt;BR /&gt;double dx = segment.EndPoint.X - segment.StartPoint.X;&lt;BR /&gt;double dy = segment.EndPoint.Y - segment.StartPoint.Y;&lt;BR /&gt;return Math.Atan2(dy, dx) * (180 / Math.PI); // Angle in degrees&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private async Task CreateAndPlacePolygons(MapPoint position, double angle, SpatialReference spatialReference, FeatureLayer layer)&lt;BR /&gt;{&lt;BR /&gt;// Adjust the offset distances for left and right polygons&lt;BR /&gt;double offsetDistanceLeft = 5; // Offset distance for left polygons&lt;BR /&gt;double offsetDistanceRight = 10; // Offset distance for right polygons&lt;/P&gt;&lt;P&gt;// Calculate perpendicular direction for left and right offsets&lt;BR /&gt;double angleLeft = angle - 90; // Perpendicular to the left&lt;BR /&gt;double angleRight = angle + 90; // Perpendicular to the right&lt;/P&gt;&lt;P&gt;// Create offset points for left and right polygons using the perpendicular angles&lt;BR /&gt;MapPoint offsetPointLeft = RotateAndMovePoint(position, angleLeft, offsetDistanceLeft, spatialReference);&lt;BR /&gt;MapPoint offsetPointRight = RotateAndMovePoint(position, angleRight, offsetDistanceRight, spatialReference);&lt;/P&gt;&lt;P&gt;// Create polygons based on the direction of the segment&lt;BR /&gt;Polygon orientedPolygonLeft = CreateOrientedPolygon(offsetPointLeft, angle, spatialReference);&lt;BR /&gt;await CreateFeatureInLayer(layer, orientedPolygonLeft);&lt;/P&gt;&lt;P&gt;Polygon orientedPolygonRight = CreateOrientedPolygon(offsetPointRight, angle, spatialReference);&lt;BR /&gt;await CreateFeatureInLayer(layer, orientedPolygonRight);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private MapPoint RotateAndMovePoint(MapPoint point, double angleDegrees, double distance, SpatialReference spatialReference)&lt;BR /&gt;{&lt;BR /&gt;double angleRadians = angleDegrees * (Math.PI / 180);&lt;/P&gt;&lt;P&gt;double offsetX = Math.Cos(angleRadians) * distance;&lt;BR /&gt;double offsetY = Math.Sin(angleRadians) * distance;&lt;/P&gt;&lt;P&gt;return MapPointBuilder.CreateMapPoint(point.X + offsetX, point.Y + offsetY, spatialReference);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private async Task CreateFeatureInLayer(FeatureLayer layer, Geometry geometry)&lt;BR /&gt;{&lt;BR /&gt;var editOperation = new EditOperation&lt;BR /&gt;{&lt;BR /&gt;Name = $"Create feature in {layer.Name}"&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;editOperation.Create(layer, geometry);&lt;/P&gt;&lt;P&gt;var result = await editOperation.ExecuteAsync();&lt;BR /&gt;if (!result) // If the result is false, the operation failed&lt;BR /&gt;{&lt;BR /&gt;var errorMessage = editOperation.ErrorMessage;&lt;BR /&gt;// Log the errorMessage or display it to understand why the operation failed&lt;BR /&gt;System.Diagnostics.Debug.WriteLine($"Error creating feature in {layer.Name}: {errorMessage}");&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private Polygon CreateOrientedPolygon(MapPoint centerPoint, double angle, SpatialReference spatialReference)&lt;BR /&gt;{&lt;BR /&gt;double width = 10; // Width of the rectangle&lt;BR /&gt;double height = 5; // Height of the rectangle&lt;/P&gt;&lt;P&gt;double halfWidth = width / 2;&lt;BR /&gt;double halfHeight = height / 2;&lt;/P&gt;&lt;P&gt;// Use MapPointBuilder to create points with a spatial reference&lt;BR /&gt;MapPoint[] cornerPoints = new MapPoint[]&lt;BR /&gt;{&lt;BR /&gt;MapPointBuilder.CreateMapPoint(centerPoint.X - halfWidth, centerPoint.Y - halfHeight, spatialReference),&lt;BR /&gt;MapPointBuilder.CreateMapPoint(centerPoint.X + halfWidth, centerPoint.Y - halfHeight, spatialReference),&lt;BR /&gt;MapPointBuilder.CreateMapPoint(centerPoint.X + halfWidth, centerPoint.Y + halfHeight, spatialReference),&lt;BR /&gt;MapPointBuilder.CreateMapPoint(centerPoint.X - halfWidth, centerPoint.Y + halfHeight, spatialReference)&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;MapPoint[] rotatedPoints = cornerPoints.Select(point =&amp;gt; RotatePoint(point, centerPoint, angle, spatialReference)).ToArray();&lt;/P&gt;&lt;P&gt;Polygon orientedPolygon = new PolygonBuilder(rotatedPoints.Select(p =&amp;gt; new Coordinate2D(p.X, p.Y)), spatialReference).ToGeometry();&lt;/P&gt;&lt;P&gt;return orientedPolygon;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private MapPoint RotatePoint(MapPoint point, MapPoint pivot, double angleDegrees, SpatialReference spatialReference)&lt;BR /&gt;{&lt;BR /&gt;double angleRadians = angleDegrees * (Math.PI / 180);&lt;/P&gt;&lt;P&gt;double cosTheta = Math.Cos(angleRadians);&lt;BR /&gt;double sinTheta = Math.Sin(angleRadians);&lt;/P&gt;&lt;P&gt;double translatedX = point.X - pivot.X;&lt;BR /&gt;double translatedY = point.Y - pivot.Y;&lt;/P&gt;&lt;P&gt;double rotatedX = translatedX * cosTheta - translatedY * sinTheta;&lt;BR /&gt;double rotatedY = translatedX * sinTheta + translatedY * cosTheta;&lt;/P&gt;&lt;P&gt;return MapPointBuilder.CreateMapPoint(rotatedX + pivot.X, rotatedY + pivot.Y, spatialReference);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private async Task DeleteIntersectingTemplates(long featureId, FeatureLayer muffePunktLayer, FeatureLayer muffeArealLayer)&lt;BR /&gt;{&lt;BR /&gt;if (!_originalGeometries.TryGetValue(featureId, out var originalGeometry))&lt;BR /&gt;{&lt;BR /&gt;return; // If not found, exit the method&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;var bufferedGeometry = GeometryEngine.Instance.Buffer(originalGeometry, 10);&lt;/P&gt;&lt;P&gt;// Use different spatial queries based on the layer type&lt;BR /&gt;await DeleteFeaturesBasedOnLayerType(muffePunktLayer, bufferedGeometry);&lt;BR /&gt;await DeleteFeaturesBasedOnLayerType(muffeArealLayer, bufferedGeometry);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private async Task DeleteFeaturesBasedOnLayerType(FeatureLayer layer, Geometry bufferedGeometry)&lt;BR /&gt;{&lt;BR /&gt;SpatialQueryFilter spatialQueryFilter = new SpatialQueryFilter&lt;BR /&gt;{&lt;BR /&gt;FilterGeometry = bufferedGeometry,&lt;BR /&gt;SpatialRelationship = SpatialRelationship.Intersects&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;List&amp;lt;Geometry&amp;gt; deletedGeometries = new List&amp;lt;Geometry&amp;gt;();&lt;BR /&gt;var featureTable = layer.GetTable();&lt;BR /&gt;if (featureTable == null) return;&lt;/P&gt;&lt;P&gt;using (var cursor = featureTable.Search(spatialQueryFilter, false))&lt;BR /&gt;{&lt;BR /&gt;while (cursor.MoveNext())&lt;BR /&gt;{&lt;BR /&gt;var feature = cursor.Current as Feature;&lt;BR /&gt;deletedGeometries.Add(feature.GetShape().Clone());&lt;/P&gt;&lt;P&gt;// Create a separate EditOperation for each feature&lt;BR /&gt;var editOperation = new EditOperation&lt;BR /&gt;{&lt;BR /&gt;Name = $"Delete feature in {layer.Name}"&lt;BR /&gt;};&lt;BR /&gt;editOperation.Delete(feature);&lt;/P&gt;&lt;P&gt;bool result = await editOperation.ExecuteAsync();&lt;BR /&gt;if (!result)&lt;BR /&gt;{&lt;BR /&gt;System.Diagnostics.Debug.WriteLine($"Failed to delete intersecting feature in {layer.Name}");&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;/LI-SPOILER&gt;&lt;P&gt;Kind regards,&amp;nbsp;&lt;BR /&gt;Marco&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2024 06:50:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-edit-operation-fails/m-p/1511386#M11913</guid>
      <dc:creator>GobiGobletsson</dc:creator>
      <dc:date>2024-07-29T06:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: First Edit Operation Fails</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-edit-operation-fails/m-p/1511631#M11914</link>
      <description>&lt;P&gt;&lt;SPAN&gt;My suspicion is in the following areas: &lt;/SPAN&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN&gt;RowEvent callbacks &lt;/SPAN&gt;&lt;SPAN&gt;are &lt;/SPAN&gt;&lt;SPAN&gt;always&lt;/SPAN&gt;&lt;SPAN&gt; called&lt;/SPAN&gt;&lt;SPAN&gt; on the QueuedTask, so there is no need to wrap your code within a QueuedTask.Run lambda (line 136)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Do not use a new edit operation in the RowEvent callbacks (line 332); instead, get an edit operation from RowChangedEventArgs, for example,&amp;nbsp;&lt;/SPAN&gt;var editOp = args.Operation&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN&gt;Please consult the &lt;A href="https://github.com/Esri/arcgis-pro-sdk/wiki/ProConcepts-Editing#row-events" target="_self"&gt;Editing Conceptual doc&lt;/A&gt; for additional details.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2024 15:15:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-edit-operation-fails/m-p/1511631#M11914</guid>
      <dc:creator>Aashis</dc:creator>
      <dc:date>2024-07-29T15:15:22Z</dc:date>
    </item>
    <item>
      <title>Re: First Edit Operation Fails</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-edit-operation-fails/m-p/1512123#M11920</link>
      <description>&lt;P&gt;Thanks for the reply.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I tried your solution alongside the provided link. Super helpful, but it didn't solve the issue - But made me wiser. I realized my mistake, and found a solution just now.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;By adding a delay&amp;nbsp;&amp;nbsp;"// Adding a small delay to ensure all initializations are complete&lt;BR /&gt;await Task.Delay(2);" at line 153 and line 305.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;My guess is, that the actions were executed inappropriately at the sametime.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 06:32:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-edit-operation-fails/m-p/1512123#M11920</guid>
      <dc:creator>GobiGobletsson</dc:creator>
      <dc:date>2024-07-30T06:32:46Z</dc:date>
    </item>
  </channel>
</rss>

