<?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 Question re: Send Command Executes after exiting command method in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/question-re-send-command-executes-after-exiting-command-method/m-p/11286454#M12428</link>
    <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working on the Civil3D add-in, and I want to send a command to select elements and then run the next line of codes using the selected objects.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this previous thread, I got an answer on how to save the selected objects into a variable. &lt;A href="https://forums.autodesk.com/t5/net/how-to-receive-selected-object-data-from-autocad-with-mouse/m-p/11279101#M73200" target="_blank"&gt;https://forums.autodesk.com/t5/net/how-to-receive-selected-object-data-from-autocad-with-mouse/m-p/11279101#M73200&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I'm having a hard time running the next line of code because the SendStringToCommand is asycnrhonous.&lt;/P&gt;&lt;P&gt;Then I ran into this thread, which was recommended in several other threads.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/net/send-command-executes-after-exiting-command-method/td-p/3882929" target="_blank"&gt;https://forums.autodesk.com/t5/net/send-command-executes-after-exiting-command-method/td-p/3882929&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I use the wrapper, I get 'null' value for the MethodInfo method and that throws an error (message: {"Value cannot be null.\r\nParameter name: method"}.&lt;BR /&gt;Does anyone know why this is giving me null value? Is it because I'm using C3D? Or versioning issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or is there any other way to run the GETOBJECT command and run next line of code in this example?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;namespace exampleTool
{

    public static class EditorInputExtensionMethods
    {
        public static PromptStatus Command_(this Editor editor, params object[] args)
        {
            if (editor == null)
                throw new ArgumentNullException("editor");
            return runCommand(editor, args);
        }

        static Func&amp;lt;Editor, object[], PromptStatus&amp;gt; runCommand = GenerateRunCommand();

        static Func&amp;lt;Editor, object[], PromptStatus&amp;gt; GenerateRunCommand()
        {
            MethodInfo method = typeof(Editor).GetMethod("RunCommand",
               BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            var instance = System.Linq.Expressions.Expression.Parameter(typeof(Editor), "instance");
            var args = Expression.Parameter(typeof(object[]), "args");
            return Expression.Lambda&amp;lt;Func&amp;lt;Editor, object[], PromptStatus&amp;gt;&amp;gt;(
               Expression.Call(instance, method, args), instance, args)
                  .Compile();
        }
    }


     public partial class NewMainWindow : System.Windows.Window
    {
        private void Get_Object(object sender, RoutedEventArgs e)
        {
            _document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor editor = _document.Editor;
            editor.Command_("._GETOBJECT");

            // next code runs..
        }
    

        ObjectId[] _currentSelection;


        [CommandMethod("GETOBJECT")]
        public void GetObject()
        {
           Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
           DocumentLock dl = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
           var ed = doc.Editor;
            

           // Request for objects to be selected in the drawing area
           PromptSelectionOptions pso = new PromptSelectionOptions();
           pso.MessageForAdding = "Select Pipes";
           PromptSelectionResult acSSPrompt = ed.GetSelection(pso);


           _currentSelection = null;
           if (acSSPrompt.Status != PromptStatus.OK)
               return;

           _currentSelection = acSSPrompt.Value.GetObjectIds();
            
        } 
    } 
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jul 2022 20:37:03 GMT</pubDate>
    <dc:creator>Soojung_Kim</dc:creator>
    <dc:date>2022-07-08T20:37:03Z</dc:date>
    <item>
      <title>Question re: Send Command Executes after exiting command method</title>
      <link>https://forums.autodesk.com/t5/net-forum/question-re-send-command-executes-after-exiting-command-method/m-p/11286454#M12428</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working on the Civil3D add-in, and I want to send a command to select elements and then run the next line of codes using the selected objects.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this previous thread, I got an answer on how to save the selected objects into a variable. &lt;A href="https://forums.autodesk.com/t5/net/how-to-receive-selected-object-data-from-autocad-with-mouse/m-p/11279101#M73200" target="_blank"&gt;https://forums.autodesk.com/t5/net/how-to-receive-selected-object-data-from-autocad-with-mouse/m-p/11279101#M73200&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I'm having a hard time running the next line of code because the SendStringToCommand is asycnrhonous.&lt;/P&gt;&lt;P&gt;Then I ran into this thread, which was recommended in several other threads.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/net/send-command-executes-after-exiting-command-method/td-p/3882929" target="_blank"&gt;https://forums.autodesk.com/t5/net/send-command-executes-after-exiting-command-method/td-p/3882929&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I use the wrapper, I get 'null' value for the MethodInfo method and that throws an error (message: {"Value cannot be null.\r\nParameter name: method"}.&lt;BR /&gt;Does anyone know why this is giving me null value? Is it because I'm using C3D? Or versioning issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or is there any other way to run the GETOBJECT command and run next line of code in this example?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;namespace exampleTool
{

    public static class EditorInputExtensionMethods
    {
        public static PromptStatus Command_(this Editor editor, params object[] args)
        {
            if (editor == null)
                throw new ArgumentNullException("editor");
            return runCommand(editor, args);
        }

        static Func&amp;lt;Editor, object[], PromptStatus&amp;gt; runCommand = GenerateRunCommand();

        static Func&amp;lt;Editor, object[], PromptStatus&amp;gt; GenerateRunCommand()
        {
            MethodInfo method = typeof(Editor).GetMethod("RunCommand",
               BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            var instance = System.Linq.Expressions.Expression.Parameter(typeof(Editor), "instance");
            var args = Expression.Parameter(typeof(object[]), "args");
            return Expression.Lambda&amp;lt;Func&amp;lt;Editor, object[], PromptStatus&amp;gt;&amp;gt;(
               Expression.Call(instance, method, args), instance, args)
                  .Compile();
        }
    }


     public partial class NewMainWindow : System.Windows.Window
    {
        private void Get_Object(object sender, RoutedEventArgs e)
        {
            _document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor editor = _document.Editor;
            editor.Command_("._GETOBJECT");

            // next code runs..
        }
    

        ObjectId[] _currentSelection;


        [CommandMethod("GETOBJECT")]
        public void GetObject()
        {
           Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
           DocumentLock dl = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
           var ed = doc.Editor;
            

           // Request for objects to be selected in the drawing area
           PromptSelectionOptions pso = new PromptSelectionOptions();
           pso.MessageForAdding = "Select Pipes";
           PromptSelectionResult acSSPrompt = ed.GetSelection(pso);


           _currentSelection = null;
           if (acSSPrompt.Status != PromptStatus.OK)
               return;

           _currentSelection = acSSPrompt.Value.GetObjectIds();
            
        } 
    } 
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 20:37:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/question-re-send-command-executes-after-exiting-command-method/m-p/11286454#M12428</guid>
      <dc:creator>Soojung_Kim</dc:creator>
      <dc:date>2022-07-08T20:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Question re: Send Command Executes after exiting command method</title>
      <link>https://forums.autodesk.com/t5/net-forum/question-re-send-command-executes-after-exiting-command-method/m-p/11286492#M12429</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since AutoCAD 2015, you have to use the built-in &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_EditorInput_Editor_Command_params_object__" target="_blank" rel="noopener"&gt;Editor.Command method&lt;/A&gt; instead of the extension method but you can only call it from the Document context (i.e. a modal dialog).&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 21:10:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/question-re-send-command-executes-after-exiting-command-method/m-p/11286492#M12429</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-07-08T21:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: Question re: Send Command Executes after exiting command method</title>
      <link>https://forums.autodesk.com/t5/net-forum/question-re-send-command-executes-after-exiting-command-method/m-p/11286579#M12430</link>
      <description>&lt;P&gt;Hi Gilles,&lt;BR /&gt;I'm running the command from windows form. So does that mean I can't run the command in the Document context? I've read that I need to use SendStringToCommand if I'm in the Application Context, but then I can't run the following code after that, as I mentioned in the post. I'm still not familiar with Document context vs Application context, so please correct me if I'm not understanding correctly here!&lt;BR /&gt;&lt;BR /&gt;I've read below information. Do you think this is the way I need to go with?&lt;BR /&gt;&lt;BR /&gt;"You can also register a command (without CommandFlags.Session) that runs in the document context, and makes calls to Editor.Command() to get the work done, and then simply invoke that registered command via SendStringToExecute() from your button click handler in the application context. That makes the solution more complicated but also more flexible, because the registered command handler can do other things besides execute an AutoCAD command. For example, If you must do something else after you run an AutoCAD command to completion, then you almost have no choice but to use a registered command, since anything that follows a call to SendStringToExecute() cannot rely on side-effects of the command(s) that are run."&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 22:24:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/question-re-send-command-executes-after-exiting-command-method/m-p/11286579#M12430</guid>
      <dc:creator>Soojung_Kim</dc:creator>
      <dc:date>2022-07-08T22:24:15Z</dc:date>
    </item>
  </channel>
</rss>

