<?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: Switching Contexts in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7707440#M29941</link>
    <description>&lt;P&gt;Please have a look at&amp;nbsp;&amp;gt;&lt;A href="https://forums.autodesk.com/t5/net/overkill-on-selection-set/m-p/7683139#M56841" target="_blank"&gt;this post&lt;/A&gt;&amp;lt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm facing one compiling issue with your example code in&lt;/P&gt;&lt;PRE&gt;        public static void Command(this DocumentCollection docs, params object[] args)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            if (doc == null)
                throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.NoDocument);
            Invoke(doc, () =&amp;gt; &lt;FONT color="#FF0000"&gt;doc.Editor&lt;/FONT&gt;.Command(args));
        }&lt;/PRE&gt;&lt;P&gt;I get "doc.Editor" red underlined with the&amp;nbsp; following description:&lt;BR /&gt;&lt;EM&gt;Error CS1929 'Editor' does not contain a definition for 'Command' and the best extension method overload 'DocumentContextHelper.Command(DocumentCollection, params object[])' requires a receiver of type 'DocumentCollection'&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;everything else is like your code, from "using System;" down to the last "}" preceding "/// USAGE EXAMPLE"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm running VS 2015 Community, targeting NET 4.0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you guess what's happening?&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 21 Jan 2018 17:02:23 GMT</pubDate>
    <dc:creator>ActivistInvestor</dc:creator>
    <dc:date>2018-01-21T17:02:23Z</dc:date>
    <item>
      <title>Switching Contexts</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7327886#M29927</link>
      <description>&lt;P&gt;I am trying to run some code/commands from my a palette, however, I&amp;nbsp;need to manually switch from Application Context to&amp;nbsp;Document Context. Does anyone know of a way this can be forced?&amp;nbsp;I have seen it in a finished product but haven't seen code behind it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am thinking using a delegate could possibly work, but not sure how I would implement it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any advice would be great.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Brent&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 05:55:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7327886#M29927</guid>
      <dc:creator>BrentBurgess1980</dc:creator>
      <dc:date>2017-08-25T05:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Contexts</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7327949#M29928</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From &lt;A href="http://through-the-interface.typepad.com/through_the_interface/2011/02/managing-drag-drop-from-a-palette-into-autocad-using-net.html" target="_blank"&gt;Kean Walmsley's blog&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;"Once again there’s our important &lt;A href="http://en.wikipedia.org/wiki/Rule_of_thumb" target="_blank"&gt;rule of thumb&lt;/A&gt; when it comes to implementing a modeless UI: rather than manually locking the current document, it’s safer to define a command – which will implicitly lock the current document – and call that from the UI via SendStringToExecute()."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another benefit of this way is the ability to directly call the command or hit enter to re-call it.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 06:47:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7327949#M29928</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-08-25T06:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Contexts</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7328422#M29929</link>
      <description>&lt;P&gt;If you do not want to use SendStringToExecute, you have to set the focus to AutoCAD window and texplicitly lock the document:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        private void btnCmd_Click(object sender, EventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            if (doc != null)
            {
                // set the focus to d'AutoCAD window 
                // before AutoCAD 2015, use: 
                // Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
                AcAp.MainWindow.Focus();
                
                // Lock the document
                using (doc.LockDocument())
                {
                    // do your stuff here&lt;BR /&gt;                    doc.Editor.UpdateScreen();
                }
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Aug 2017 10:16:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7328422#M29929</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-08-25T10:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Contexts</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7329038#M29930</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/496655"&gt;@BrentBurgess1980&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;I am trying to run some code/commands from my a palette, however, I&amp;nbsp;need to manually switch from Application Context to&amp;nbsp;Document Context. Does anyone know of a way this can be forced?&amp;nbsp;I have seen it in a finished product but haven't seen code behind it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am thinking using a delegate could possibly work, but not sure how I would implement it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice would be great.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Brent&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is some code that will simplify what you want to do, along with an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows;

namespace Autodesk.AutoCAD.ApplicationServices
{
   public static class DocumentContextHelper
   {
      static Action action = null;

      const CommandFlags flags = CommandFlags.NoHistory
         | CommandFlags.NoMultiple
         | CommandFlags.NoActionRecording;

      /// &amp;lt;summary&amp;gt;
      /// Initiates execution of code in the document context
      /// from the application context. The code to be executed 
      /// in the document context is passed in the delegate. 
      ///
      /// If this API is called from the document context, the 
      /// delegate will execute synchronously. If called from 
      /// the application context, the delegate will execute 
      /// asynchronously when control returns to AutoCAD.
      /// &amp;lt;/summary&amp;gt;
      /// &amp;lt;param name="docs"&amp;gt;The Document, which must be the
      /// active document in the editor&amp;lt;/param&amp;gt;
      /// &amp;lt;param name="callback"&amp;gt;A delegate that takes no arguments&amp;lt;/param&amp;gt;
      
      public static void Invoke(this Document doc, Action callback)
      {
         if(doc == null)
            throw new ArgumentNullException("doc");
         if(callback == null)
            throw new ArgumentNullException("action");
         if(action != null)
            throw new InvalidOperationException("reentry not supported");
         var docs = Application.DocumentManager;
         if(doc != docs.MdiActiveDocument)
            throw new InvalidOperationException("Document is not active");
         if(docs.IsApplicationContext)
         {
            action = callback;
            doc.SendStringToExecute("ANONYMOUS_DOCUMENT_COMMAND\n", true, false, false);
         }
         else
         {
            callback();
         }
      }

      /// &amp;lt;summary&amp;gt;
      /// An extension method for the DocumentCollection that executes 
      /// the given command input in the document context. The command
      /// input is executed in the active document. If there is no active
      /// document, an exception is raised. 
      ///
      /// Do NOT call this from the delegate passed to Invoke(). This API 
      /// is intended as an alternative to the Invoke() method, that you 
      /// can use if you simply need to execute a series of commands from 
      /// the application context and don't need to do anything else after 
      /// the commands have been executed.
      /// &amp;lt;/summary&amp;gt;
      /// &amp;lt;param name="docs"&amp;gt;The DocumentCollection&amp;lt;/param&amp;gt;
      /// &amp;lt;param name="args"&amp;gt;The command arguments&amp;lt;/param&amp;gt;
      
      public static void Command(this DocumentCollection docs, params object[] args)
      {
         Document doc = Application.DocumentManager.MdiActiveDocument;
         if(doc == null)
            throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.NoDocument);
         Invoke(doc, () =&amp;gt; doc.Editor.Command(args));
      }

      /// &amp;lt;summary&amp;gt;
      /// Controls the value of the CMDECHO system variable 
      /// while the delegate passed to Invoke() is running. 
      /// This can be set to true for debugging calls to 
      /// Editor.Command() (it is false by default).
      /// &amp;lt;/summary&amp;gt;
      
      public static bool CmdEcho
      {
         get;
         set;
      }

      [CommandMethod("ANONYMOUS_DOCUMENT_COMMAND", flags)]
      public static void commandHandler()
      {
         if(action != null)
         {
            object cmdecho = Application.GetSystemVariable("CMDECHO");
            Application.SetSystemVariable("CMDECHO", CmdEcho ? 1 : 0);
            try
            {
               action();
            }
            finally
            {
               Application.SetSystemVariable("CMDECHO", cmdecho);
               action = null;
            }
         }
      }
   }
}

/// USAGE EXAMPLE

namespace InvokeExample
{
   using Autodesk.AutoCAD.ApplicationServices;
   using Application = Autodesk.AutoCAD.ApplicationServices.Application;
   using System.Windows.Forms;

   /// &amp;lt;summary&amp;gt;
   /// An example UserControl hosted by the PalletteSet below.
   /// 
   /// This example shows how to execute code in the document context,
   /// from the application context. The button on the UserControl
   /// calls the Invoke() method and passes a delegate that will 
   /// execute in the document context asynchronously. 
   /// 
   /// When the button is clicked, the delegate executes and
   /// calls the Editor's Command() method to draw a circle.
   /// &amp;lt;/summary&amp;gt;
      
   public class MyUserControl : UserControl
   {
      Button button;

      public MyUserControl()
      {
         button = new Button();
         button.Text = "Draw a Circle";
         button.Left = 10;
         button.Top = 10;
         button.AutoSize = true;
         button.Click += new EventHandler(button_Click);
         this.Controls.Add(button);
      }

      void button_Click(object sender, EventArgs e)
      {
         Document doc = Application.DocumentManager.MdiActiveDocument;
         if(doc != null &amp;amp;&amp;amp; doc.Editor.IsQuiescent)
         {
            this.Enabled = false;
            doc.Invoke(
               delegate()
               {
                  doc.Editor.Command("CIRCLE", "10,10", "5");
                  this.Enabled = true;
               }
            );
         }
      }
   }

   // A PaletteSet that hosts the above UserControl

   public class MyPaletteSet : PaletteSet
   {
      MyUserControl control;

      public MyPaletteSet()
         : base("MyPaletteSet")
      {
         control = new MyUserControl();
         Add("MyUserControl", control);
         this.DockEnabled = DockSides.None;
         this.Visible = true;
         this.Dock = DockSides.None;
      }

      protected override void Dispose(bool disposing)
      {
         if(control != null)
         {
            control.Dispose();
            control = null;
         }
         base.Dispose(disposing);
      }

      /// &amp;lt;summary&amp;gt;
      /// A command to create/show the example PaletteSet
      /// &amp;lt;/summary&amp;gt;
      
      static MyPaletteSet instance;

      [CommandMethod("SHOWMYPALETTESET", CommandFlags.Session)]
      public static void ShowMyPaletteSet()
      {
         if(instance == null)
         {
            instance = new MyPaletteSet();
         }
         instance.Visible = true;
      }
   }
}&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Aug 2017 14:42:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7329038#M29930</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-08-25T14:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Contexts</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7332152#M29931</link>
      <description>&lt;P&gt;I can see how it is meant to work, but when it gets to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;action = callback;&lt;BR /&gt; doc.SendStringToExecute("ANONYMOUS_DOCUMENT_COMMAND\n", true, false, false);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unknown command "ANONYMOUS_DOCUMENT_COMMAND". &amp;nbsp;Press F1 for help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas on this?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2017 02:53:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7332152#M29931</guid>
      <dc:creator>BrentBurgess1980</dc:creator>
      <dc:date>2017-08-28T02:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Contexts</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7332197#M29932</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/496655"&gt;@BrentBurgess1980&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;I can see how it is meant to work, but when it gets to&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;action = callback;&lt;BR /&gt;doc.SendStringToExecute("ANONYMOUS_DOCUMENT_COMMAND\n", true, false, false);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unknown command "ANONYMOUS_DOCUMENT_COMMAND". &amp;nbsp;Press F1 for help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas on this?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Did you convert that code to VB or something?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ANONYMOUS_DOCUMENT_COMMAND is just a regular command defined using the CommandMethod attribute.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can type its name into the command prompt, and if it is defined, there should be no Unknown command message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there is, it means the command is not being recognized (possibly because there's an exception being thrown when the assembly is loaded).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2017 03:55:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7332197#M29932</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-08-28T03:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Contexts</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7332247#M29933</link>
      <description>&lt;P&gt;Not converted. Using C#. Not sure what I was doing, but it recognises it now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have noticed that the Invoke callback is being set to the button click, rather than what I assumed would be the doc.Editor.SendCommand(......)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 650px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/394733iC650D9A22F4FD3CB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is throwing an exception&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture1.PNG" style="width: 705px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/394735iE63BBC67D0207BFC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.PNG" alt="Capture1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have I done something wrong with the implementation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Brent&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2017 04:57:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7332247#M29933</guid>
      <dc:creator>BrentBurgess1980</dc:creator>
      <dc:date>2017-08-28T04:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Contexts</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7332347#M29934</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/496655"&gt;@BrentBurgess1980&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Not converted. Using C#. Not sure what I was doing, but it recognises it now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have noticed that the Invoke callback is being set to the button click, rather than what I assumed would be the doc.Editor.SendCommand(......)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is throwing an exception&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have I done something wrong with the implementation?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Brent&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;What release of AutoCAD are you using?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I very quickly ripped that code example from a much more complicated code base, and hastily forget to include this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;BR /&gt;/// Important: If and only if the containing assembly uses the 
/// CommandClass attribute on classes that have command 
/// methods, the following line MUST not be commented out.

// [assembly: CommandClass(typeof(Autodesk.AutoCAD.ApplicationServices.DocumentContextHelper))]&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;The above might explain why the ANONYMOUS_DOCUMENT_COMMAND isn't recognized, but I see you've fixed that.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2017 06:56:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7332347#M29934</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-08-28T06:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Contexts</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7332460#M29935</link>
      <description>&lt;P&gt;was using 2014, but got it to work on 2017. Thanks heaps for the help!!!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2017 07:55:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7332460#M29935</guid>
      <dc:creator>BrentBurgess1980</dc:creator>
      <dc:date>2017-08-28T07:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Contexts</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7707090#M29936</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm facing one compiling issue with your example code in&lt;/P&gt;
&lt;PRE&gt;        public static void Command(this DocumentCollection docs, params object[] args)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            if (doc == null)
                throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.NoDocument);
            Invoke(doc, () =&amp;gt; &lt;FONT color="#FF0000"&gt;doc.Editor&lt;/FONT&gt;.Command(args));
        }&lt;/PRE&gt;
&lt;P&gt;I get "doc.Editor" red underlined with the&amp;nbsp; following description:&lt;BR /&gt;&lt;EM&gt;Error CS1929 'Editor' does not contain a definition for 'Command' and the best extension method overload 'DocumentContextHelper.Command(DocumentCollection, params object[])' requires a receiver of type 'DocumentCollection'&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;everything else is like your code, from "using System;" down to the last "}" preceding "/// USAGE EXAMPLE"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm running VS 2015 Community, targeting NET 4.0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you guess what's happening?&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2018 09:15:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7707090#M29936</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-01-21T09:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Contexts</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7707093#M29937</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Editor.Command() method came with AutoCAD 2015. For prior version, you can use Tony "DiningPhilosopher" Tanzillo's wrapper for the non-public RunCommand() method (second reply of &lt;STRONG&gt;&lt;A href="https://forums.autodesk.com/t5/net/send-command-executes-after-exiting-command-method/td-p/3882929" target="_blank"&gt;this thread&lt;/A&gt;&lt;/STRONG&gt;).&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2018 09:21:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7707093#M29937</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-01-21T09:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Contexts</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7707106#M29938</link>
      <description>&lt;P&gt;thanks Gile&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm on my nth start with NET, pushed by the threat of VBA being abandoned sometime in the (next?) future&lt;/P&gt;
&lt;P&gt;maybe this is the good one!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;back to the present issue, your piece of advice let me have a compiling code, along with the addition of&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using System.Reflection;
using System.Linq.Expressions;
&lt;/PRE&gt;
&lt;P&gt;and I'll go on and watch what happens...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;meanwhile, since I was brought here by&amp;nbsp;&lt;A href="https://forums.autodesk.com/t5/net/paletteset-pallete-and-other-classes-relations/td-p/7631940" target="_blank"&gt;this thread&lt;/A&gt;,&amp;nbsp;&lt;SPAN class=""&gt;I'd like to know your feedback on ActivistInvestor post #11 where he proposed his PaletteSet managing pattern as opposed to yours and J&lt;SPAN&gt;uergen_Becke&lt;/SPAN&gt;&amp;nbsp;one: do you agree with him? If not, why?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;Finally do you think that the PaletteSet pattern is the best way to build some tool and make people use some AutoCAD "custom program"?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;thank you&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2018 09:55:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7707106#M29938</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-01-21T09:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Contexts</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7707178#M29939</link>
      <description>&lt;P&gt;ActivistInvestor is a very experimented programmer and, from my part I always pay attention to its advices.&lt;/P&gt;
&lt;P&gt;In the topic you linked, despite the fact both Juergen_Becke's and mine do work, ActivistInvestor's implementation is a 'better practice'.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2018 11:44:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7707178#M29939</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-01-21T11:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Contexts</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7707410#M29940</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;thanks Gile&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm on my nth start with NET, pushed by the threat of VBA being abandoned sometime in the (next?) future&lt;/P&gt;&lt;P&gt;maybe this is the good one!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;back to the present issue, your piece of advice let me have a compiling code, along with the addition of&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System.Reflection;
using System.Linq.Expressions;&lt;/PRE&gt;&lt;P&gt;and I'll go on and watch what happens...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;meanwhile, since I was brought here by&amp;nbsp;&lt;A href="https://forums.autodesk.com/t5/net/paletteset-pallete-and-other-classes-relations/td-p/7631940" target="_blank"&gt;this thread&lt;/A&gt;,&amp;nbsp;&lt;SPAN&gt;I'd like to know your feedback on ActivistInvestor post #11 where he proposed his PaletteSet managing pattern as opposed to yours and J&lt;SPAN&gt;uergen_Becke&lt;/SPAN&gt;&amp;nbsp;one: do you agree with him? If not, why?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Finally do you think that the PaletteSet pattern is the best way to build some tool and make people use some AutoCAD "custom program"?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;thank you&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The patterns that you see repeated in 'basic examples' are often a result of someone else using the pattern in earlier examples. They tend to propagate,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the case of the PaletteSet, I would give &lt;A href="http://www.through-the-interface.typepad.com" target="_blank"&gt;through-the-interface&lt;/A&gt;,&amp;nbsp;and &lt;A href="http://www.adndevblog.typepad.com/autocad/" target="_blank"&gt;possibly others&lt;/A&gt; from Autodesk the credit for&amp;nbsp;the very first examples, none of which used what I consider the 'best practice' of inheritance (all of the PaletteSet-based UI's that come in the box, like the ribbon, do use inheritance). But in their defense, many of those early published examples were written&amp;nbsp;back when the PaletteSet class was sealed, which means that deriving classes from it was not possible. As I mentioned in the thread you referenced, around the time the Ribbon appeared, the PaletteSet class was unsealed, and also had some of its members made virtual/overridable, which was done largely in support of the ribbon (although IMO, the PaletteSet shouldn't have been sealed from the beginning).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A&amp;nbsp;PaletteSet is not too different from a Windows Form in terms of its purpose and use. When you build a Windows Form, the IDE generates the derived class for you, and places its initialization code in a method called InitializeComponent(), which is called from the constructor of the derived class. That's really how a component should be implemented, so that it has no dependence on other code outside its class. Because the PaletteSet class is not sealed, it also has virtual, overridable members which can only be leveraged through inheritance, so the intent of the design&amp;nbsp;was clearly that the consumer of the PaletteSet class use inheritance as the means of gaining full access to the functionality it provides.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You might also want to see &lt;A href="https://forums.autodesk.com/t5/net/overkill-on-selection-set/m-p/7683139#M56841" target="_blank"&gt;this thread&lt;/A&gt; for a more-complete example that includes the code you where having problems with above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2018 17:01:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7707410#M29940</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-01-21T17:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Contexts</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7707440#M29941</link>
      <description>&lt;P&gt;Please have a look at&amp;nbsp;&amp;gt;&lt;A href="https://forums.autodesk.com/t5/net/overkill-on-selection-set/m-p/7683139#M56841" target="_blank"&gt;this post&lt;/A&gt;&amp;lt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm facing one compiling issue with your example code in&lt;/P&gt;&lt;PRE&gt;        public static void Command(this DocumentCollection docs, params object[] args)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            if (doc == null)
                throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.NoDocument);
            Invoke(doc, () =&amp;gt; &lt;FONT color="#FF0000"&gt;doc.Editor&lt;/FONT&gt;.Command(args));
        }&lt;/PRE&gt;&lt;P&gt;I get "doc.Editor" red underlined with the&amp;nbsp; following description:&lt;BR /&gt;&lt;EM&gt;Error CS1929 'Editor' does not contain a definition for 'Command' and the best extension method overload 'DocumentContextHelper.Command(DocumentCollection, params object[])' requires a receiver of type 'DocumentCollection'&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;everything else is like your code, from "using System;" down to the last "}" preceding "/// USAGE EXAMPLE"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm running VS 2015 Community, targeting NET 4.0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you guess what's happening?&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2018 17:02:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-contexts/m-p/7707440#M29941</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-01-21T17:02:23Z</dc:date>
    </item>
  </channel>
</rss>

