<?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 Re: Edit event for Utility Network in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1191783#M8402</link>
    <description>&lt;P&gt;Here is the code that I tested on both versioned and non-versioned. Which on fine on&amp;nbsp;non-versioned.&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;internal class Module1 : Module
	{
		//For the events
		private Dictionary&amp;lt;string, List&amp;lt;SubscriptionToken&amp;gt;&amp;gt; _rowevents = new Dictionary&amp;lt;string, List&amp;lt;SubscriptionToken&amp;gt;&amp;gt;();
		private static List&amp;lt;SubscriptionToken&amp;gt; rowCreateTokens = new List&amp;lt;SubscriptionToken&amp;gt;();
		private static List&amp;lt;SubscriptionToken&amp;gt; rowChangeTokens = new List&amp;lt;SubscriptionToken&amp;gt;();
		private static List&amp;lt;SubscriptionToken&amp;gt; rowDeleteTokens = new List&amp;lt;SubscriptionToken&amp;gt;();

		private static Module1 _this = null;

		/// &amp;lt;summary&amp;gt;
		/// Retrieve the singleton instance to this module here
		/// &amp;lt;/summary&amp;gt;
		public static Module1 Current
		{
			get
			{
				return _this ?? (_this = (Module1)FrameworkApplication.FindModule("CodePan_Module"));
			}
		}

		#region Overrides
		/// &amp;lt;summary&amp;gt;
		/// Called by Framework when ArcGIS Pro is closing
		/// &amp;lt;/summary&amp;gt;
		/// &amp;lt;returns&amp;gt;False to prevent Pro from closing, otherwise True&amp;lt;/returns&amp;gt;
		protected override bool CanUnload()
		{
			//TODO - add your business logic
			//return false to ~cancel~ Application close
			return true;
		}

		protected override bool Initialize()
        {
			EditTemplateEvent();

			ActiveMapViewChangedEvent.Subscribe(OnActiveMapViewChanged);

			return base.Initialize();
        }

		private async void OnActiveMapViewChanged(ActiveMapViewChangedEventArgs activeMapViewChangedEventArgs)
        {
			await subscribeToRowEvent();
		}

		void EditTemplateEvent()
        {
			ActiveTemplateChangedEvent.Subscribe(OnActiveTemplateChanged);

			void OnActiveTemplateChanged(ActiveTemplateChangedEventArgs args)
			{
				// return if incoming template is null
				if (args.IncomingTemplate == null)
				{
					return;
				}
				string templateName = args.IncomingTemplate.Name;
				var insp = args.IncomingTemplate.Inspector;
				switch (templateName)
				{
					case "Point":
						insp["Field"] = $"{templateName} test";
						break;
					case "Line":
						insp["Field"] = $"{templateName} test";
						break;
					case "Polygon":
						insp["Field"] = $"{templateName} test";
						break;
				}
				QueuedTask.Run(() =&amp;gt; {
					args.IncomingTemplate.ActivateDefaultToolAsync();
				});

			}
		}

		protected Task subscribeToRowEvent()
		{
			return QueuedTask.Run(() =&amp;gt;
			{

				if (MapView.Active != null &amp;amp;&amp;amp; MapView.Active.Map != null)
				{
					var editLayers = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;();
					if (editLayers.Count() == 0)
					{
						return;
				}


					foreach (var layer in editLayers)
					{
						//Listen for row events on a layer
						var layerTable = layer.GetTable();

						//subscribe to row events
						SubscriptionToken rowCreateToken = RowCreatedEvent.Subscribe(onRowCreateEvent, layerTable);
						SubscriptionToken rowChangeToken = RowChangedEvent.Subscribe(onRowChangeEvent, layerTable);
						SubscriptionToken rowDeleteToken = RowDeletedEvent.Subscribe(onRowDeleteEvent, layerTable);

						rowCreateTokens.Add(rowCreateToken);
						rowChangeTokens.Add(rowChangeToken);
						rowDeleteTokens.Add(rowDeleteToken);
					}
				}
			});
		}

		protected void onRowCreateEvent(RowChangedEventArgs args)
		{
			//MessageBox.Show("onRowCreateEvent " + args.EditType.ToString());
			Row row = args.Row;
			Feature feature = args.Row as Feature;
			Geometry editGeometry = feature["Shape"] as Geometry;

			FeatureLayer featureLayer = MapView.Active.Map.FindLayers("DSDDistrict", false).OfType&amp;lt;FeatureLayer&amp;gt;().First(l =&amp;gt; l.Name.Equals("DSDDistrict"));
            SpatialQueryFilter spatialQueryFilter = new SpatialQueryFilter
            {
                FilterGeometry = editGeometry,
                SpatialRelationship = SpatialRelationship.Intersects
            };

			RowCursor rowCursor = featureLayer.Search(spatialQueryFilter);
			string region = "";
			while (rowCursor.MoveNext())
			{
				Row districtRow = rowCursor.Current;
				region = districtRow["DIV"] as string;
			}

			row["Field"] = $"CUSTOM VALUE {region}";
			
			row.Store();
		}

		protected void onRowChangeEvent(RowChangedEventArgs args)
		{
			//MessageBox.Show("onRowChangeEvent " + args.EditType.ToString());
		}

		protected void onRowDeleteEvent(RowChangedEventArgs args)
		{
			//MessageBox.Show("onRowDeleteEvent " + args.EditType.ToString());
		}

		#endregion Overrides 

	}&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 13 Jul 2022 06:58:19 GMT</pubDate>
    <dc:creator>OscarYam</dc:creator>
    <dc:date>2022-07-13T06:58:19Z</dc:date>
    <item>
      <title>Edit event for Utility Network</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1191427#M8380</link>
      <description>&lt;P&gt;Hi, I am new to ArcGIS Pro SDK. Using ArcGIS Pro 2.9 and Utility Network version 5.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on an ArcGIS Pro add-in project. I need to implement an automation function that assigns attributes when users create a new feature. For example, assign a region code by the location where the user clicked which requires a spatial query.&lt;/P&gt;&lt;P&gt;I tried&amp;nbsp;RowCreatedEvent but it is not working on a branch versioned&amp;nbsp;&lt;SPAN&gt;feature service.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How can I achieve my goal similar to the ArcObject OnCreateFeature event? If not, is there any workaround?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2022 02:45:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1191427#M8380</guid>
      <dc:creator>OscarYam</dc:creator>
      <dc:date>2022-07-12T02:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: Edit event for Utility Network</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1191534#M8385</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/479712"&gt;@OscarYam&lt;/a&gt;&amp;nbsp;Could you please share your feature creation code snippet so we can answer you correctly?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2022 13:55:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1191534#M8385</guid>
      <dc:creator>Aashis</dc:creator>
      <dc:date>2022-07-12T13:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: Edit event for Utility Network</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1191629#M8391</link>
      <description>&lt;P&gt;I'll add that you should take a look at&amp;nbsp;attribute rules. &amp;nbsp;These are scripts that you can configure on a&amp;nbsp;geodatabase that run in response to edit events on specific feature classes or subtypes. &amp;nbsp;Doing a spatial query and assigning a value to an attribute is&amp;nbsp;&lt;EM&gt;exactly&lt;/EM&gt; what they are designed to do.&lt;/P&gt;&lt;P&gt;Attribute Rules also work cross-platform, and will fire outside of ArcGIS Pro (e.g., runtime and server)&lt;/P&gt;&lt;P&gt;--Rich&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2022 17:21:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1191629#M8391</guid>
      <dc:creator>RichRuh</dc:creator>
      <dc:date>2022-07-12T17:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Edit event for Utility Network</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1191782#M8401</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Is it possible to create an attribute rule that obtains a sequence number from SQL Server and assigns it to an attribute?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2022 06:48:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1191782#M8401</guid>
      <dc:creator>OscarYam</dc:creator>
      <dc:date>2022-07-13T06:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: Edit event for Utility Network</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1191783#M8402</link>
      <description>&lt;P&gt;Here is the code that I tested on both versioned and non-versioned. Which on fine on&amp;nbsp;non-versioned.&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;internal class Module1 : Module
	{
		//For the events
		private Dictionary&amp;lt;string, List&amp;lt;SubscriptionToken&amp;gt;&amp;gt; _rowevents = new Dictionary&amp;lt;string, List&amp;lt;SubscriptionToken&amp;gt;&amp;gt;();
		private static List&amp;lt;SubscriptionToken&amp;gt; rowCreateTokens = new List&amp;lt;SubscriptionToken&amp;gt;();
		private static List&amp;lt;SubscriptionToken&amp;gt; rowChangeTokens = new List&amp;lt;SubscriptionToken&amp;gt;();
		private static List&amp;lt;SubscriptionToken&amp;gt; rowDeleteTokens = new List&amp;lt;SubscriptionToken&amp;gt;();

		private static Module1 _this = null;

		/// &amp;lt;summary&amp;gt;
		/// Retrieve the singleton instance to this module here
		/// &amp;lt;/summary&amp;gt;
		public static Module1 Current
		{
			get
			{
				return _this ?? (_this = (Module1)FrameworkApplication.FindModule("CodePan_Module"));
			}
		}

		#region Overrides
		/// &amp;lt;summary&amp;gt;
		/// Called by Framework when ArcGIS Pro is closing
		/// &amp;lt;/summary&amp;gt;
		/// &amp;lt;returns&amp;gt;False to prevent Pro from closing, otherwise True&amp;lt;/returns&amp;gt;
		protected override bool CanUnload()
		{
			//TODO - add your business logic
			//return false to ~cancel~ Application close
			return true;
		}

		protected override bool Initialize()
        {
			EditTemplateEvent();

			ActiveMapViewChangedEvent.Subscribe(OnActiveMapViewChanged);

			return base.Initialize();
        }

		private async void OnActiveMapViewChanged(ActiveMapViewChangedEventArgs activeMapViewChangedEventArgs)
        {
			await subscribeToRowEvent();
		}

		void EditTemplateEvent()
        {
			ActiveTemplateChangedEvent.Subscribe(OnActiveTemplateChanged);

			void OnActiveTemplateChanged(ActiveTemplateChangedEventArgs args)
			{
				// return if incoming template is null
				if (args.IncomingTemplate == null)
				{
					return;
				}
				string templateName = args.IncomingTemplate.Name;
				var insp = args.IncomingTemplate.Inspector;
				switch (templateName)
				{
					case "Point":
						insp["Field"] = $"{templateName} test";
						break;
					case "Line":
						insp["Field"] = $"{templateName} test";
						break;
					case "Polygon":
						insp["Field"] = $"{templateName} test";
						break;
				}
				QueuedTask.Run(() =&amp;gt; {
					args.IncomingTemplate.ActivateDefaultToolAsync();
				});

			}
		}

		protected Task subscribeToRowEvent()
		{
			return QueuedTask.Run(() =&amp;gt;
			{

				if (MapView.Active != null &amp;amp;&amp;amp; MapView.Active.Map != null)
				{
					var editLayers = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;();
					if (editLayers.Count() == 0)
					{
						return;
				}


					foreach (var layer in editLayers)
					{
						//Listen for row events on a layer
						var layerTable = layer.GetTable();

						//subscribe to row events
						SubscriptionToken rowCreateToken = RowCreatedEvent.Subscribe(onRowCreateEvent, layerTable);
						SubscriptionToken rowChangeToken = RowChangedEvent.Subscribe(onRowChangeEvent, layerTable);
						SubscriptionToken rowDeleteToken = RowDeletedEvent.Subscribe(onRowDeleteEvent, layerTable);

						rowCreateTokens.Add(rowCreateToken);
						rowChangeTokens.Add(rowChangeToken);
						rowDeleteTokens.Add(rowDeleteToken);
					}
				}
			});
		}

		protected void onRowCreateEvent(RowChangedEventArgs args)
		{
			//MessageBox.Show("onRowCreateEvent " + args.EditType.ToString());
			Row row = args.Row;
			Feature feature = args.Row as Feature;
			Geometry editGeometry = feature["Shape"] as Geometry;

			FeatureLayer featureLayer = MapView.Active.Map.FindLayers("DSDDistrict", false).OfType&amp;lt;FeatureLayer&amp;gt;().First(l =&amp;gt; l.Name.Equals("DSDDistrict"));
            SpatialQueryFilter spatialQueryFilter = new SpatialQueryFilter
            {
                FilterGeometry = editGeometry,
                SpatialRelationship = SpatialRelationship.Intersects
            };

			RowCursor rowCursor = featureLayer.Search(spatialQueryFilter);
			string region = "";
			while (rowCursor.MoveNext())
			{
				Row districtRow = rowCursor.Current;
				region = districtRow["DIV"] as string;
			}

			row["Field"] = $"CUSTOM VALUE {region}";
			
			row.Store();
		}

		protected void onRowChangeEvent(RowChangedEventArgs args)
		{
			//MessageBox.Show("onRowChangeEvent " + args.EditType.ToString());
		}

		protected void onRowDeleteEvent(RowChangedEventArgs args)
		{
			//MessageBox.Show("onRowDeleteEvent " + args.EditType.ToString());
		}

		#endregion Overrides 

	}&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 13 Jul 2022 06:58:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1191783#M8402</guid>
      <dc:creator>OscarYam</dc:creator>
      <dc:date>2022-07-13T06:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: Edit event for Utility Network</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1191956#M8405</link>
      <description>&lt;P&gt;Yes. &amp;nbsp;Attribute rules are written using a scripting language called Arcade, which provides a function called GetNextSequenceValue(). &amp;nbsp;More information on&amp;nbsp;attribute rules can be found starting &lt;A href="https://pro.arcgis.com/en/pro-app/2.9/help/data/geodatabases/overview/an-overview-of-attribute-rules.htm" target="_self"&gt;here.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;--Rich&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2022 16:35:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1191956#M8405</guid>
      <dc:creator>RichRuh</dc:creator>
      <dc:date>2022-07-13T16:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: Edit event for Utility Network</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1192126#M8414</link>
      <description>&lt;P&gt;Thank you for your assistance. I'm going to study the materials that you mentioned. Hope this will work in my situation. I will update this post if I have any updates.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 06:27:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1192126#M8414</guid>
      <dc:creator>OscarYam</dc:creator>
      <dc:date>2022-07-14T06:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: Edit event for Utility Network</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1193761#M8448</link>
      <description>&lt;P data-unlink="true"&gt;Now I am having a problem with getting the sequence number.&lt;/P&gt;&lt;P data-unlink="true"&gt;I would like to test out the basic concept before the actual implementation, so I tested on a geodatabase.&lt;/P&gt;&lt;P data-unlink="true"&gt;I created a File geoDatabase and created the sequence "ThePointSequence" by using&amp;nbsp;&lt;SPAN&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/2.9/tool-reference/data-management/create-database-sequence.htm" target="_blank" rel="noopener"&gt;Create Database Sequence&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;tool. Then I had a test run that failed(see in the attachments).&lt;/SPAN&gt;&lt;/P&gt;&lt;P data-unlink="true"&gt;&lt;SPAN&gt;Then I try the function&amp;nbsp;GetNextSequenceValue() that you suggested. There was an Error Invalid Arcade expression.&lt;/SPAN&gt;&lt;/P&gt;&lt;P data-unlink="true"&gt;&lt;SPAN&gt;So, is there any mistake in my testing? Or do I start on the wrong path?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 04:34:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/edit-event-for-utility-network/m-p/1193761#M8448</guid>
      <dc:creator>OscarYam</dc:creator>
      <dc:date>2022-07-20T04:34:23Z</dc:date>
    </item>
  </channel>
</rss>

