<?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 Get new objectID form EditOperation.Split() in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-new-objectid-form-editoperation-split/m-p/1277641#M9642</link>
    <description>&lt;P&gt;I am working on an add-in function that splits line features. I ran some experiments and found that split will modify the original feature and add a new one. Now, I have to implement business logic that modifies the value of the new one in the same split operation. How do I retrieve the object id of the new feature and proceed with the chained operation?&lt;/P&gt;</description>
    <pubDate>Wed, 12 Apr 2023 03:15:23 GMT</pubDate>
    <dc:creator>OscarYam</dc:creator>
    <dc:date>2023-04-12T03:15:23Z</dc:date>
    <item>
      <title>Get new objectID form EditOperation.Split()</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-new-objectid-form-editoperation-split/m-p/1277641#M9642</link>
      <description>&lt;P&gt;I am working on an add-in function that splits line features. I ran some experiments and found that split will modify the original feature and add a new one. Now, I have to implement business logic that modifies the value of the new one in the same split operation. How do I retrieve the object id of the new feature and proceed with the chained operation?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 03:15:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-new-objectid-form-editoperation-split/m-p/1277641#M9642</guid>
      <dc:creator>OscarYam</dc:creator>
      <dc:date>2023-04-12T03:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: Get new objectID form EditOperation.Split()</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-new-objectid-form-editoperation-split/m-p/1277650#M9643</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I use workflow which is written below.&lt;/P&gt;&lt;P&gt;1. Set EditOperation property&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic9577.html" target="_blank" rel="noopener"&gt;SelectModifiedFeatures&lt;/A&gt;&amp;nbsp;to false.&lt;/P&gt;&lt;P&gt;2. Set EditOperation property &lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic9578.html" target="_blank" rel="noopener"&gt;SelectNewFeatures&lt;/A&gt;&amp;nbsp;to true.&lt;/P&gt;&lt;P&gt;3. Make your split operation and execute it.&lt;/P&gt;&lt;P&gt;4. Get splited feature layer selection. It will contain object ids of new created parts.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 05:18:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-new-objectid-form-editoperation-split/m-p/1277650#M9643</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2023-04-12T05:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Get new objectID form EditOperation.Split()</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-new-objectid-form-editoperation-split/m-p/1278587#M9675</link>
      <description>&lt;P&gt;Or you can try to use the RowCreatedEvent to capture all new rows (and their object ids).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;try
{
  var mapView = MapView.Active;
  if (mapView == null) return;

  var polygonLayer = mapView.Map.GetLayersAsFlattenedList()
      .OfType&amp;lt;BasicFeatureLayer&amp;gt;().FirstOrDefault (lyr =&amp;gt; lyr.Name == "TestPolygons");
  var lineLayer = mapView.Map.GetLayersAsFlattenedList()
      .OfType&amp;lt;BasicFeatureLayer&amp;gt;().FirstOrDefault(lyr =&amp;gt; lyr.Name == "TestLines");

  if (polygonLayer == null || lineLayer == null)
  {
    throw new Exception($@"The split action requires both Layers: TestPolygons and TestLines");
  }
  QueuedTask.Run(() =&amp;gt;
  {
    ArcGIS.Core.Events.SubscriptionToken token = null;
    try
    {
      // create an edit operation
      EditOperation splitOperation = new()
      {
        Name = "Split polygons",
        ProgressMessage = "Working...",
        CancelMessage = "Operation canceled.",
        ErrorMessage = "Error splitting polygons",
        SelectModifiedFeatures = false,
        SelectNewFeatures = false
      };

      var splitTargetSelectionDictionary = new Dictionary&amp;lt;MapMember, List&amp;lt;long&amp;gt;&amp;gt;
        {
          { polygonLayer, polygonLayer.GetSelection().GetObjectIDs().ToList() }
        };

      var splittingSelectionDictionary = new Dictionary&amp;lt;MapMember, List&amp;lt;long&amp;gt;&amp;gt;
        {
          { lineLayer, lineLayer.GetSelection().GetObjectIDs().ToList() }
        };

      // initialize a list of ObjectIDs that to be split (selected TestPolygons)
      var splitTargetSelectionSet = SelectionSet.FromDictionary(splitTargetSelectionDictionary);

      // initialize the list of ObjectIDs that are used for the splitting (selected TestLines)
      var splittingSelectionSet = SelectionSet.FromDictionary(splittingSelectionDictionary);

      // perform the Split operation:
      // To be split (selected TestPolygons)
      // Used for the splitting (selected TestLines)
      splitOperation.Split(splitTargetSelectionSet, splittingSelectionSet);

      // start listening to RowCreate events in order to collect all new rows
      List&amp;lt;long&amp;gt; newOids = new();
      token = ArcGIS.Desktop.Editing.Events.RowCreatedEvent.Subscribe((ev) =&amp;gt;
      {
        newOids.Add (ev.Row.GetObjectID());
      }, polygonLayer.GetTable());

      var result = splitOperation.Execute();
      if (result != true || splitOperation.IsSucceeded != true)
        throw new Exception($@"Edit 1 failed: {splitOperation.ErrorMessage}");
      System.Diagnostics.Trace.WriteLine($@"Number of new rows: {newOids.Count}");
    }
    catch
    {
      throw;
    }
    finally
    {
      if (token != null)
        ArcGIS.Desktop.Editing.Events.RowCreatedEvent.Unsubscribe(token);
    }
  });
}
catch (Exception ex)
{
  MessageBox.Show(ex.ToString());
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 22:10:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-new-objectid-form-editoperation-split/m-p/1278587#M9675</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2023-04-13T22:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: Get new objectID form EditOperation.Split()</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-new-objectid-form-editoperation-split/m-p/1281724#M9725</link>
      <description>&lt;P&gt;Thank you for your assistance. But sadly&amp;nbsp;&lt;SPAN&gt;RowCreatedEvent does not work in my case since the data involve Utility Network. I ran many tests before this project started but can't get&amp;nbsp;RowCreatedEvent to work with the Utility Network properly.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 01:32:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-new-objectid-form-editoperation-split/m-p/1281724#M9725</guid>
      <dc:creator>OscarYam</dc:creator>
      <dc:date>2023-04-24T01:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Get new objectID form EditOperation.Split()</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-new-objectid-form-editoperation-split/m-p/1281725#M9726</link>
      <description>&lt;P&gt;Thank you for your inspiration. I manage to achieve what I need to do. I will post a proper script later.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 01:35:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-new-objectid-form-editoperation-split/m-p/1281725#M9726</guid>
      <dc:creator>OscarYam</dc:creator>
      <dc:date>2023-04-24T01:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: Get new objectID form EditOperation.Split()</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-new-objectid-form-editoperation-split/m-p/1281728#M9727</link>
      <description>&lt;P&gt;Big thanks to&amp;nbsp;&lt;A href="https://community.esri.com/t5/user/viewprofilepage/user-id/42133" target="_blank" rel="noopener"&gt;&lt;SPAN class=""&gt;GintautasKmieliauskas&lt;/SPAN&gt;&lt;/A&gt;. With GintautasKmieliauskas's&amp;nbsp;&lt;SPAN&gt;inspiration, I come up with something that may be dumb but suits my case.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;return QueuedTask.Run(() =&amp;gt;
{
	MapPoint splitPoint = ActiveMapView.ClientToMap(args.ClientPoint);
	if (splitPoint == null)
	{
		return;
	}
	// Get SelectedFeatures by MapSelectionChangedEvent()
	Dictionary&amp;lt;MapMember, List&amp;lt;long&amp;gt;&amp;gt; selectedFeature = SelectedFeatures;
	if (selectedFeature.Count == 1)
	{
		KeyValuePair&amp;lt;MapMember, List&amp;lt;long&amp;gt;&amp;gt; keyValuePair = selectedFeature.ElementAtOrDefault(0);
		if (keyValuePair.Key is FeatureLayer featureLayer &amp;amp;&amp;amp; keyValuePair.Value.Count == 1)
		{
			// get the target line feature
			QueryFilter filter = new QueryFilter
			{
				ObjectIDs = keyValuePair.Value,
			};
			RowCursor cursor = featureLayer.Search(filter);
			cursor.MoveNext();
			Feature splitTargetLine = (Feature)cursor.Current;

			EditOperation splitEditOperation = new EditOperation();
			splitEditOperation.SelectNewFeatures = true;
			// split the line feature at split point
			splitEditOperation.Split((Layer)keyValuePair.Key, keyValuePair.Value[0], splitPoint);
			
			if (splitEditOperation.Execute())
			{
				// get the new SelectedFeatures by MapSelectionChangedEvent()
				Dictionary&amp;lt;MapMember, List&amp;lt;long&amp;gt;&amp;gt; newSelectedFeature = SelectedFeatures;
				KeyValuePair&amp;lt;MapMember, List&amp;lt;long&amp;gt;&amp;gt; NewKeyValuePair = newSelectedFeature.ElementAtOrDefault(0);
				
				// get the new line feature
				filter.ObjectIDs = NewKeyValuePair.Value;
				cursor = featureLayer.Search(filter);
				cursor.MoveNext();
				Feature newFeature = (Feature)cursor.Current;
				
				// create map point for add new point
				MapPoint connectionPoint = MapPointBuilderEx.CreateMapPoint(((MapPoint)splitPoint));
				
				// Create Chained Operation
				EditOperation createOperation = splitEditOperation.CreateChainedOperation();
				FeatureLayer deviceLayer = MapView.Active.Map.FindLayers("point layer", true).OfType&amp;lt;FeatureLayer&amp;gt;().First(l =&amp;gt; l.Name.Equals("point layer"));
				
				// point attribute list
				Dictionary&amp;lt;string, object&amp;gt; pointValues = new Dictionary&amp;lt;string, object&amp;gt;();
				pointValues.Add("field1", "value");
				createOperation.Modify(newFeature, "field2", "value");
				createOperation.Modify(splitTargetLine, "field2", "value");
				
				// add the connection point at split point
				createOperation.Create(deviceLayer, splitPoint, pointValues);
				if (createOperation.Execute())
				{
					MessageBox.Show("Line breaked.", "Breaks", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
				}
			}
		}
		else
		{
			MessageBox.Show("Please select 1 feature only.", "Breaks", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
		}
	}
	else
	{
		MessageBox.Show("Please select 1 feature only.", "Breaks", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
	}
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 02:07:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-new-objectid-form-editoperation-split/m-p/1281728#M9727</guid>
      <dc:creator>OscarYam</dc:creator>
      <dc:date>2023-04-24T02:07:14Z</dc:date>
    </item>
  </channel>
</rss>

