Send Command Executes after exiting command method

Send Command Executes after exiting command method

chockalingam
Advocate Advocate
7,811 Views
25 Replies
Message 1 of 26

Send Command Executes after exiting command method

chockalingam
Advocate
Advocate

Hi,

  I used send command for Export Layout

  But the line only executes after exiting command method.

 Can anyone help in this case.

 

thanks in advance.

0 Likes
7,812 Views
25 Replies
Replies (25)
Message 21 of 26

Anonymous
Not applicable

Hi Everyone! I want to use this code in .net 2.0 and there is no LINQ. So I am using a library called LINQBridge to implement LINQ Objects but still i have problem with piece of code that needs linq.lambda.expressions ! Can Anyone Help Me? (In my case i need to use commands syncronously in autocad 2013)

0 Likes
Message 22 of 26

_gile
Consultant
Consultant

Hi,

 

AutoCAD 2013 installs the .NET Framewok 4.0.

Why don't you target it?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 23 of 26

Anonymous
Not applicable

Hi again!

Sorry i was wrong about my case. I need to run it for Autocad 2007, 2008 and 2009.

Any help would be appreciated

0 Likes
Message 24 of 26

_gile
Consultant
Consultant

You can try this way (also from Tony Tanzillo) which does not use Linq.

 

    public static class EditoExtension
    {
        static MethodInfo runCommand = 
            typeof(Editor).GetMethod("RunCommand", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

        public static PromptStatus Command(this Editor ed, params object[] args)
        {
            if (Application.DocumentManager.IsApplicationContext)
                throw new InvalidOperationException("Invalid execution context for Command()");
            if (ed.Document != Application.DocumentManager.MdiActiveDocument)
                throw new InvalidOperationException("Document is not active");
            return (PromptStatus)runCommand.Invoke(ed, new object[] { args });
        }
    }

 

 

If it still doesn't work, you have to P/Invoke the unmanaged acedCmd method.

 

        [System.Security.SuppressUnmanagedCodeSecurity]
        [DllImport("acad.exe", EntryPoint = "acedCmd",
            CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        extern static private int acedCmd(IntPtr resbuf);

        /// <summary>
        /// Call an AutoCAD command (works synchronously).
        /// </summary>
        /// <param name="args">A ResultBuffer containing the command name followed by command inputs.</param>
        public static void Command(ResultBuffer args)
        {
            acedCmd(args.UnmanagedObject);
        }

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 25 of 26

Anonymous
Not applicable

Thank you very much _gile.

I will test it to see if it works or not.

0 Likes
Message 26 of 26

Soojung_Kim
Enthusiast
Enthusiast

Hi, I'm trying to use this method but ran into an issue where I get 'null' for the MethodInfo object. I made a post about it. If anyone can help me out, that would be great. Thanks! https://forums.autodesk.com/t5/net/question-re-send-command-executes-after-exiting-command-method/td...

0 Likes