<?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: Send synchronization command  by  p/invoke with acedCmd in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/send-synchronization-command-by-p-invoke-with-acedcmd/m-p/7772215#M27461</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;thank &amp;nbsp;you ！&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;i find &amp;nbsp;that &amp;nbsp;the &amp;nbsp;ed.command &amp;nbsp;can't be used in &amp;nbsp;CommandFlags.Session!&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;In &amp;nbsp;comandFlags.Session,how &amp;nbsp;to &amp;nbsp;send &amp;nbsp;synchronization command?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;As&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;mentioned, there's no way to execute commands synchronously from the application context (e.g, CommandFlags.Session).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are a few ways around that, including Autodesk's own ExecuteInCommandContextAsync(), which is one way of doing what the code included in &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;nbsp;does.&lt;/P&gt;</description>
    <pubDate>Mon, 12 Feb 2018 20:55:19 GMT</pubDate>
    <dc:creator>ActivistInvestor</dc:creator>
    <dc:date>2018-02-12T20:55:19Z</dc:date>
    <item>
      <title>Send synchronization command  by  p/invoke with acedCmd</title>
      <link>https://forums.autodesk.com/t5/net-forum/send-synchronization-command-by-p-invoke-with-acedcmd/m-p/7769795#M27456</link>
      <description>&lt;P&gt;I wan't send &amp;nbsp;a&amp;nbsp;synchronization command &amp;nbsp;by &amp;nbsp;p/invoke with acedCmd &amp;nbsp;in autocad map 2015&lt;/P&gt;&lt;P&gt;my code like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[System.Security.SuppressUnmanagedCodeSecurity]
        [DllImport("accore.dll", EntryPoint = "acedCmd", CallingConvention = CallingConvention.Cdecl)]
        private static extern int acedCmd(IntPtr vlist);

        /// &amp;lt;summary&amp;gt;
       
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="endCommandByUser"&amp;gt;end command type&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="ldnode"&amp;gt;params&amp;lt;/param&amp;gt;
        public static void MyCommand(bool endCommandByUser, ResultBuffer rb)
        {
            ResultBuffer rbend = new ResultBuffer();
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                string currCmdName = doc.CommandInProgress;
                int result = acedCmd(rb.UnmanagedObject);
                if (endCommandByUser)
                {
                    rbend.Add(new TypedValue((int)LispDataType.Text, "\\"));
                }
                while (doc.CommandInProgress != currCmdName)
                {
                    acedCmd(rbend.UnmanagedObject);
                }
            }
            catch { }
            finally
            {
                rb.Dispose();
                rbend.Dispose();
            }
        }
    
        [CommandMethod("MyZoomE")]
        public void myzoome()
        {
           

            ResultBuffer rb = new ResultBuffer();
           
            int A = (int)LispDataType.Text;//A=5005
            rb.Add(new TypedValue((int)LispDataType.Text, "zoom"));
            rb.Add(new TypedValue(5005, "E"));
            rb.Add(new TypedValue(5005, ""));
            
            MyCommand(false, rb);

        }&lt;/PRE&gt;&lt;P&gt;when i send &amp;nbsp; the &amp;nbsp;"MyZoomE" command &amp;nbsp;,I &amp;nbsp;get &amp;nbsp;the &amp;nbsp;return result &amp;nbsp; &amp;nbsp;is &amp;nbsp;"-5001"&lt;/P&gt;&lt;P&gt;what's &amp;nbsp;wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 06:33:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/send-synchronization-command-by-p-invoke-with-acedcmd/m-p/7769795#M27456</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-12T06:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: Send synchronization command  by  p/invoke with acedCmd</title>
      <link>https://forums.autodesk.com/t5/net-forum/send-synchronization-command-by-p-invoke-with-acedcmd/m-p/7769820#M27457</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;You do not need to P/Invoke acedCmd, until AutoCAD 2015 there's a new&lt;A href="http://through-the-interface.typepad.com/through_the_interface/2014/03/autocad-2015-calling-commands.html" target="_blank"&gt; Editor.Command() method&lt;/A&gt; which works synchronously.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("MyZoomE")]
        public void myzoome()
        {
            var ed = Application.DocumentManager.MdiActiveDocument.Editor;
            ed.Command("_.zoom", "_extents");
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also have a look at a little &lt;A href="http://www.theswamp.org/index.php?topic=49124.msg542370#msg542370" target="_blank"&gt;comparison between Command and CommandAsync&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 06:49:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/send-synchronization-command-by-p-invoke-with-acedcmd/m-p/7769820#M27457</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-02-12T06:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: Send synchronization command  by  p/invoke with acedCmd</title>
      <link>https://forums.autodesk.com/t5/net-forum/send-synchronization-command-by-p-invoke-with-acedcmd/m-p/7769846#M27458</link>
      <description>&lt;P&gt;thank &amp;nbsp;you ！&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;i find &amp;nbsp;that &amp;nbsp;the &amp;nbsp;ed.command &amp;nbsp;can't be used in &amp;nbsp;CommandFlags.Session!&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;In &amp;nbsp;comandFlags.Session,how &amp;nbsp;to &amp;nbsp;send &amp;nbsp;synchronization command?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 07:04:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/send-synchronization-command-by-p-invoke-with-acedcmd/m-p/7769846#M27458</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-12T07:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: Send synchronization command  by  p/invoke with acedCmd</title>
      <link>https://forums.autodesk.com/t5/net-forum/send-synchronization-command-by-p-invoke-with-acedcmd/m-p/7769873#M27459</link>
      <description>&lt;P&gt;As far as know, there is no way to execute commands&amp;nbsp;synchronously from the application context.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can find some helper to switch context provided by &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt; in &lt;A href="https://forums.autodesk.com/t5/net/switching-contexts/m-p/7329038#M54890" target="_blank"&gt;this post&lt;/A&gt;..&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 07:16:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/send-synchronization-command-by-p-invoke-with-acedcmd/m-p/7769873#M27459</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-02-12T07:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Send synchronization command  by  p/invoke with acedCmd</title>
      <link>https://forums.autodesk.com/t5/net-forum/send-synchronization-command-by-p-invoke-with-acedcmd/m-p/7772043#M27460</link>
      <description>&lt;P&gt;You could try the Editor.CommandAsync or&amp;nbsp;Document.SendStringToExecute methods.&amp;nbsp; Make sure to use the await keyword with&amp;nbsp;&lt;SPAN&gt;Editor.CommandAsync.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 20:02:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/send-synchronization-command-by-p-invoke-with-acedcmd/m-p/7772043#M27460</guid>
      <dc:creator>ambrosl</dc:creator>
      <dc:date>2018-02-12T20:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: Send synchronization command  by  p/invoke with acedCmd</title>
      <link>https://forums.autodesk.com/t5/net-forum/send-synchronization-command-by-p-invoke-with-acedcmd/m-p/7772215#M27461</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;thank &amp;nbsp;you ！&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;i find &amp;nbsp;that &amp;nbsp;the &amp;nbsp;ed.command &amp;nbsp;can't be used in &amp;nbsp;CommandFlags.Session!&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;In &amp;nbsp;comandFlags.Session,how &amp;nbsp;to &amp;nbsp;send &amp;nbsp;synchronization command?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;As&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;mentioned, there's no way to execute commands synchronously from the application context (e.g, CommandFlags.Session).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are a few ways around that, including Autodesk's own ExecuteInCommandContextAsync(), which is one way of doing what the code included in &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;nbsp;does.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 20:55:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/send-synchronization-command-by-p-invoke-with-acedcmd/m-p/7772215#M27461</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-02-12T20:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Send synchronization command  by  p/invoke with acedCmd</title>
      <link>https://forums.autodesk.com/t5/net-forum/send-synchronization-command-by-p-invoke-with-acedcmd/m-p/7773034#M27462</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1706559"&gt;@ambrosl&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;You could try the Editor.CommandAsync or&amp;nbsp;Document.SendStringToExecute methods.&amp;nbsp; Make sure to use the await keyword with&amp;nbsp;&lt;SPAN&gt;Editor.CommandAsync.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The OP requirement is to synchronously run a command in application context (CommandFlags.Session).&lt;/P&gt;
&lt;P&gt;Document.SendStringToExecute runs asynchronously.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Editor.CommandAsync&lt;/SPAN&gt; as EditorCommand only works in document context.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 06:49:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/send-synchronization-command-by-p-invoke-with-acedcmd/m-p/7773034#M27462</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-02-13T06:49:38Z</dc:date>
    </item>
  </channel>
</rss>

