<?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: How to get selected feature(s) from selection tool? in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-feature-s-from-selection-tool/m-p/1226492#M8977</link>
    <description>&lt;P&gt;Thank you for your solution. Here is what I come up with to fit my situation.&lt;/P&gt;&lt;P&gt;I added the following code in module1.cs like you said. And created a class to store selections so I can access the&amp;nbsp;selected features within my addin project.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected override bool Initialize()
{
	SubscribleMapSelectionChangedEvent();
	return base.Initialize();
}

private void SubscribleMapSelectionChangedEvent()
{
	ArcGIS.Desktop.Mapping.Events.MapSelectionChangedEvent.Subscribe((args) =&amp;gt; {
		//If u are only interested in one particular map...
		if (args.Map.Name == "My map")
		{
			#if DEBUG
			System.Diagnostics.Debug.WriteLine("Selection changed");
			#endif
			var sel = args.Selection;//This is what is selected
			if (sel.Count == 0)
			{
				#if DEBUG
				System.Diagnostics.Debug.WriteLine(" 0 features selected");
				#endif
				return;
			}
			else
			{
				CommonObject.GlobalVariables.SelectedFeatures = sel.ToDictionary();
			}
		}
	});
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Oct 2022 03:31:16 GMT</pubDate>
    <dc:creator>OscarYam</dc:creator>
    <dc:date>2022-10-28T03:31:16Z</dc:date>
    <item>
      <title>How to get selected feature(s) from selection tool?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-feature-s-from-selection-tool/m-p/1220622#M8874</link>
      <description>&lt;P&gt;I would like to create a button that updates the selected feature's attribute. When I started coding, I found that I cannot get the selected feature after I use the default selection tool(the tools under esri_mapping_selectToolPalette). Is it any method to get the selected feature from the default selection tool?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 10:35:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-feature-s-from-selection-tool/m-p/1220622#M8874</guid>
      <dc:creator>OscarYam</dc:creator>
      <dc:date>2022-10-11T10:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to get selected feature(s) from selection tool?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-feature-s-from-selection-tool/m-p/1220904#M8877</link>
      <description>&lt;P&gt;Subscribe to the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic12812.html" target="_self"&gt;MapSelectionChangedEvent&lt;/A&gt;. Any changes to the map selection via selection tool, via custom selection, etc. will fire the event.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;ArcGIS.Desktop.Mapping.Events.MapSelectionChangedEvent.Subscribe((args) =&amp;gt; {
   //If u are only interested in one particular map...
   if (args.Map.Name == "The Map Name I am Interested In") {
     System.Diagnostics.Debug.WriteLine("Selection changed");
     var sel = args.Selection;//This is what is selected
     if (sel.Count == 0) {
       System.Diagnostics.Debug.WriteLine(" 0 features selected");
       return;
     }
     //enumerate current selection - a series of keyvalue pairs
     //key is the MapMember, Value is the list of OIDs
     foreach(var kvp in sel.ToDictionary()) {
  
       var oids = kvp.Value; //OIDs of the selected features
       var oid_str_list = oids.Select(oid =&amp;gt; oid.ToString()).ToList();
       var oid_str = string.Join(",", oid_str_list);
       System.Diagnostics.Debug.WriteLine(
                     $"{kvp.Key.Name}: {oid_str}");

       if (kvp.Key is BasicFeatureLayer fl) {
         //TODO selection is on a vector layer...
       }
       else if (kvp.Key is StandaloneTable tbl) {
         //TODO selection is on a table...
       }
       //else if (....)
       //{
       //   etc,etc.
       //}
    }
   }
 });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: In 2.x, the event argument syntax is slightly different. The Selection property is a Dictionary so there is no sel.ToDictionary() as such.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 21:23:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-feature-s-from-selection-tool/m-p/1220904#M8877</guid>
      <dc:creator>CharlesMacleod</dc:creator>
      <dc:date>2022-10-11T21:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to get selected feature(s) from selection tool?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-feature-s-from-selection-tool/m-p/1226017#M8970</link>
      <description>&lt;P&gt;Would you mind explaining more about where should these codes go to? Should those codes go to Module1.cs or the button.cs? I am using Arcgis pro 3.0.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 07:06:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-feature-s-from-selection-tool/m-p/1226017#M8970</guid>
      <dc:creator>OscarYam</dc:creator>
      <dc:date>2022-10-27T07:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to get selected feature(s) from selection tool?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-feature-s-from-selection-tool/m-p/1226321#M8973</link>
      <description>&lt;P&gt;The Module is probably the best place. There is an initialize method in the Module which is probably a good spot. I would also set your module autoLoad attribute to true in the Config.daml.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; &amp;lt;modules&amp;gt;
    &amp;lt;insertModule id="...." className="Module1" autoLoad="true"
       caption="Module1"&amp;gt;&lt;/LI-CODE&gt;&lt;LI-CODE lang="csharp"&gt;internal class Module1 : Module {

  private static Module1 _this = null;
  ...
  protected override bool Initialize()
  {
  	//TODO subscribe to the mapping event here

  	return true;
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 18:58:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-feature-s-from-selection-tool/m-p/1226321#M8973</guid>
      <dc:creator>CharlesMacleod</dc:creator>
      <dc:date>2022-10-27T18:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get selected feature(s) from selection tool?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-feature-s-from-selection-tool/m-p/1226492#M8977</link>
      <description>&lt;P&gt;Thank you for your solution. Here is what I come up with to fit my situation.&lt;/P&gt;&lt;P&gt;I added the following code in module1.cs like you said. And created a class to store selections so I can access the&amp;nbsp;selected features within my addin project.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected override bool Initialize()
{
	SubscribleMapSelectionChangedEvent();
	return base.Initialize();
}

private void SubscribleMapSelectionChangedEvent()
{
	ArcGIS.Desktop.Mapping.Events.MapSelectionChangedEvent.Subscribe((args) =&amp;gt; {
		//If u are only interested in one particular map...
		if (args.Map.Name == "My map")
		{
			#if DEBUG
			System.Diagnostics.Debug.WriteLine("Selection changed");
			#endif
			var sel = args.Selection;//This is what is selected
			if (sel.Count == 0)
			{
				#if DEBUG
				System.Diagnostics.Debug.WriteLine(" 0 features selected");
				#endif
				return;
			}
			else
			{
				CommonObject.GlobalVariables.SelectedFeatures = sel.ToDictionary();
			}
		}
	});
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 03:31:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-feature-s-from-selection-tool/m-p/1226492#M8977</guid>
      <dc:creator>OscarYam</dc:creator>
      <dc:date>2022-10-28T03:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to get selected feature(s) from selection tool?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-feature-s-from-selection-tool/m-p/1226499#M8979</link>
      <description>&lt;P&gt;Nice work Oscar. One thing I thought I would mention: The module class is actually already global throughout the addin (by design). All classes can access it via the special "singleton" property called "Current".&lt;/P&gt;&lt;P&gt;Therefore, if you wanted, you could add a "SelectedFeatures" property to your module class directly and access it that way. So it could look something like this:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class Module1 : Module  {
    ...
    private Dictionary&amp;lt;MapMember, List&amp;lt;long&amp;gt;&amp;gt; _selFeatures;

    //Any (non-private) module property or method can be accessed from 
    //anywhere within the addin
    internal Dictionary&amp;lt;MapMember, List&amp;lt;long&amp;gt;&amp;gt; SelectedFeatures =&amp;gt; 
     _selFeatures ??= new Dictionary&amp;lt;MapMember, List&amp;lt;long&amp;gt;&amp;gt;();

    //elsewhere...access the property via Module1.Current...
    foreach(var kvp in Module1.Current.SelectedFeatures) {&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 05:32:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-feature-s-from-selection-tool/m-p/1226499#M8979</guid>
      <dc:creator>CharlesMacleod</dc:creator>
      <dc:date>2022-10-28T05:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to get selected feature(s) from selection tool?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-feature-s-from-selection-tool/m-p/1226939#M8989</link>
      <description>&lt;P&gt;Thanks for your additional info, cheers!&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 04:35:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-feature-s-from-selection-tool/m-p/1226939#M8989</guid>
      <dc:creator>OscarYam</dc:creator>
      <dc:date>2022-10-31T04:35:42Z</dc:date>
    </item>
  </channel>
</rss>

