<?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: Maintain selection after command is complete in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/maintain-selection-after-command-is-complete/m-p/13433112#M288</link>
    <description>&lt;P&gt;That’s just the way AutoCAD works. When you run a command, the selection is unhighlighted. However you still have the selection set. Just run your code on the entities in the selection set.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 18 Apr 2025 20:15:19 GMT</pubDate>
    <dc:creator>Ed__Jobe</dc:creator>
    <dc:date>2025-04-18T20:15:19Z</dc:date>
    <item>
      <title>Maintain selection after command is complete</title>
      <link>https://forums.autodesk.com/t5/net-forum/maintain-selection-after-command-is-complete/m-p/13433017#M286</link>
      <description>&lt;P&gt;I have commands that ask the user to select objects.&amp;nbsp; Nothing fancy just like below.&amp;nbsp; After the command does what it needs to do, the objects are unselected.&amp;nbsp; What is causing the unselecting of the objects?&amp;nbsp; Is there a way to maintain the selection?&lt;BR /&gt;&lt;BR /&gt;Ideally, the objects would stay selected because there are subsequent commands that will be run that will require the same objects to be selected again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;        // Request for objects to be selected in the drawing area
        PromptSelectionResult acSSPrompt = doc.Editor.GetSelection();

        // If the prompt status is OK, objects were selected
        if (acSSPrompt.Status == PromptStatus.OK)
        {
            SelectionSet acSSet = acSSPrompt.Value;

            // Step through the objects in the selection set
            foreach (SelectedObject acSSObj in acSSet)
            {
                // Do something here.
            }
        }
        tr.Commit();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Apr 2025 19:05:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/maintain-selection-after-command-is-complete/m-p/13433017#M286</guid>
      <dc:creator>mdolanVQYAA</dc:creator>
      <dc:date>2025-04-18T19:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Maintain selection after command is complete</title>
      <link>https://forums.autodesk.com/t5/net-forum/maintain-selection-after-command-is-complete/m-p/13433102#M287</link>
      <description>&lt;P&gt;You add &lt;STRONG&gt;CommandFlags.Redraw&lt;/STRONG&gt; to your CommandMethod attribute, and then call the Editor's &lt;STRONG&gt;SetImpliedSelection()&lt;/STRONG&gt; method to specify the objects to be left selected after the command ends.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;[CommandMethod("MYCOMMAND", CommandFlags.UsePickSet | CommandFlags.Redraw)]
public static void MyCommand()
{
   var doc = Application.DocumentManager.MdiActiveDocument;
   
   PromptSelectionResult result = doc.Editor.GetSelection();

   if(result.Status == PromptStatus.OK)
   {
      SelectionSet acSSet = result.Value;

      // Step through the objects in the selection set
      foreach(SelectedObject acSSObj in acSSet)
      {
         // Do something here.
      }
      
      doc.Editor.SetImpliedSelection(acSSet.GetObjectIds());
   }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another tip:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Don't iterate over a selection set's SelectedObjects if you don't need them. In most cases, you only need the ObjectIds of the selected entities, which you can get by calling &lt;STRONG&gt;SelectionSet.GetObjectIds&lt;/STRONG&gt;(), and you can iterate over those instead. The SelectedObject class that's enumerated by the SelectionSet class has some overhead, because it exposes not only the objectId of the selected object, but also selection metadata (e.g., how the object was selected, and selection parameters, such as the pick point, window/crossing polygon vertices, and so on). If you don't need that information, then you can avoid the overhead of marshaling it to manged code by just iterating over the ObjectIds instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, instead of:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;foreach(SelectedObject acSSObj in acSSet)
{
   // Do something here.
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is less-costly to do this:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;foreach(ObjectId id in acSSet.GetObjectIds())
{
   // Do something here.
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Apr 2025 20:45:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/maintain-selection-after-command-is-complete/m-p/13433102#M287</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2025-04-18T20:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Maintain selection after command is complete</title>
      <link>https://forums.autodesk.com/t5/net-forum/maintain-selection-after-command-is-complete/m-p/13433112#M288</link>
      <description>&lt;P&gt;That’s just the way AutoCAD works. When you run a command, the selection is unhighlighted. However you still have the selection set. Just run your code on the entities in the selection set.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Apr 2025 20:15:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/maintain-selection-after-command-is-complete/m-p/13433112#M288</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2025-04-18T20:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: Maintain selection after command is complete</title>
      <link>https://forums.autodesk.com/t5/net-forum/maintain-selection-after-command-is-complete/m-p/13433147#M289</link>
      <description>&lt;P&gt;ActivistInvestor, CommandFlags.UsePickSet was exactly what I was looking for.&amp;nbsp; Worked like a charm.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Apr 2025 20:41:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/maintain-selection-after-command-is-complete/m-p/13433147#M289</guid>
      <dc:creator>mdolanVQYAA</dc:creator>
      <dc:date>2025-04-18T20:41:17Z</dc:date>
    </item>
  </channel>
</rss>

