Running AutoCAD VBA from C# .NET

by Fenton Webb

Here’s how to invoke a function Public Sub Test() declared in VBA from .NET; use acedCmd() and run –vbarun

// how to call VBA from .NET    #if AC2013        [DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedCmd")]    #else        [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedCmd")]    #endif        private static extern int acedCmd(System.IntPtr vlist);        [CommandMethod("callVBA")]        public void callVBA()        {          ResultBuffer rb = new ResultBuffer();          // RTSTR = 5005          rb.Add(new TypedValue(5005, "_.-vbarun"));          rb.Add(new TypedValue(5005, "test"));          // start vbarun running 'ThisDrawing.Test()          acedCmd(rb.UnmanagedObject);        }

Comments

One response to “Running AutoCAD VBA from C# .NET”

  1. Hi Fenton!
    There is another method with AcadApplication.RunMacro

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading