Invoke command in loop by ResultBuffer with Autocad 2015

Invoke command in loop by ResultBuffer with Autocad 2015

Anonymous
Not applicable
1,579 Views
3 Replies
Message 1 of 4

Invoke command in loop by ResultBuffer with Autocad 2015

Anonymous
Not applicable

Hello,

 

I have this code: (from here: http://www.acadnetwork.com/index.php?topic=292.0 )

 

   // Replace "accore.dll" by "acad.exe" for AutoCAD versions prior to 2013
        [System.Security.SuppressUnmanagedCodeSecurity]
        [System.Runtime.InteropServices.DllImport("accore.dll", EntryPoint = "acedCmd", CharSet = System.Runtime.InteropServices.CharSet.Unicode, CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
        extern static private int acedCmd(IntPtr resbuf);
        [CommandMethod("offpl")]

        public void cmdOffset()
        {

            ResultBuffer rb = new ResultBuffer();

            // RTSTR = 5005

            rb.Add(new TypedValue(5005, "_.OFFSET"));

            // start the insert command

            acedCmd(rb.UnmanagedObject);



            bool quit = false;

            // loop round while the insert command is active

            while (!quit)
            {

                // see what commands are active

                string cmdNames = (string)Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("CMDNAMES");

                // if the INSERT command is active

                if (cmdNames.ToUpper().IndexOf("OFFSET") >= 0)
                {

                    // then send a PAUSE to the command line

                    rb = new ResultBuffer();

                    // RTSTR = 5005 - send a user pause to the command line

                    rb.Add(new TypedValue(5005, "\\"));

                    acedCmd(rb.UnmanagedObject);

                }

                else

                    // otherwise quit

                    quit = true;

            }

        }

 In AC 2007 it works fine. I've changed acad.exe to accore.dll, but nothing happens.

I'm not getting even "Unknown command".

 

Can someone help me?

0 Likes
Accepted solutions (1)
1,580 Views
3 Replies
Replies (3)
Message 2 of 4

_gile
Consultant
Consultant
Accepted solution

Hi,

 

No more need to P/Invoke acedCmd with AutoCAD 2015.

Have a look at the Editor.Command() and Edtor.CommandAsync() methods.

You may have a look at this thread.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 4

Anonymous
Not applicable

I will look at this tomorrow. Thanks Smiley Happy

0 Likes
Message 4 of 4

_gile
Consultant
Consultant

You can try this way:

 

[CommandMethod("offpl")]
public void cmdOffset()
{
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
    ed.Command("_.offset");
    while (true)
    {
        try { ed.Command(@"\"); }
        catch { break; }
    }
}

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes