.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Synchronize call commands in AutoCAD versions before 2015

10 REPLIES 10
Reply
Message 1 of 11
dali0312
429 Views, 10 Replies

Synchronize call commands in AutoCAD versions before 2015

I can use the Command method of Editor to synchronously call commands in AutoCAD 2015 and above versions. However, there is no replaceable method for use in versions below 2015. May I ask if anyone has a good solution? Thanks.
10 REPLIES 10
Message 2 of 11
_gile
in reply to: dali0312

Hi,

There was a wrapper for the non-public RunCommand() method written by Tony Tanzillo ( @ActivistInvestor or @DiningPhilosopher ) which worked the same as A2015+ Editor.Command, unfortunately this thread has been archived deleted.

I refound an older version of this wrapper at TheSwamp, and the "refection free" version, always at TheSwamp.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 11
ActivistInvestor
in reply to: dali0312

As @_gile has already mentioned, the code I posted here a little over 10 years ago, that solves your problem, has been deleted by Autodesk.

 

Because I harbor no contempt for users of old/outdated releases of AutoCAD, Here it is again:

 

using System.Reflection;
using System;
using System.Linq.Expressions;

namespace Autodesk.AutoCAD.EditorInput
{
   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<Editor, object[], PromptStatus> runCommand = Generate;

      static PromptStatus Generate(this Editor editor, params object[] arguments)
      {
         MethodInfo method = typeof(Editor).GetMethod("RunCommand",
            BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
         var instance = Expression.Parameter(typeof(Editor), "instance");
         var args = Expression.Parameter(typeof(object[]), "args");
         runCommand = Expression.Lambda<Func<Editor, object[], PromptStatus>>(
            Expression.Call(instance, method, args), instance, args)
               .Compile();
         return runCommand(editor, arguments);
      }
   }
}

 

 

Message 4 of 11

If DocumentCollection.IsApplicationContext == true, You can't use the command line or the Command() wrapper for the RunCommand method.What should I do.Is the execution order different from Command versions 15 and above

Message 5 of 11


@2890459225 wrote:

If DocumentCollection.IsApplicationContext == true, You can't use the command line or the Command() wrapper for the RunCommand method.What should I do.Is the execution order different from Command versions 15 and above


 

In AutoCAD 2016 or later, the DocumentCollection's ExecuteInCommandContextAsync() method can be used to solve that problem.

 

ExecuteInCommandContextAsync() is Autodesk's implementation of my original solution to that problem, that works in any AutoCAD release going back to AutoCAD 2006 or 2007 (although I never tested it with releases that old, as I originally wrote it in the AutoCAD 2012 time-frame).

 

That solution is discussed in this post, which also requires this file.

Message 6 of 11

15 以下版本如何使用同步命令发送

Message 7 of 11
2890459225
in reply to: _gile

I tried this method but it didn't work and the command sent was not executed

Message 8 of 11

自己翻译成英文

Message 9 of 11

How to use synchronous command to send in versions below 15

Message 10 of 11


@2890459225 wrote:

I tried this method but it didn't work and the command sent was not executed


The code @_gile linked to, and the code that I posted in this thread all work, so if your attempt to use that code failed, it is an error on your part. 

 

If the code doesn't work for you, post your code that attempts to use it, otherwise we're not interested in nothing more than "didn't work".

Message 11 of 11


@2890459225 wrote:

How to use synchronous command to send in versions below 15


See the replies above, with code and links to more code.  The code in the above post adds the Command() method to the Editor in versions < 2015.  If you add that code to your project, you can use the Command() method in versions older than 2015 in the same way you would use the built-in Command() method in later versions.

 

I can't make it any simpler than that.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report