Alexander Rivilis wrote:
> Try this code:
> [code]
> using System;
> using System.Runtime.InteropServices;
> using Autodesk.AutoCAD.Runtime;
>
> [assembly: CommandClass(typeof(ClassLibrary.Class))]
>
> namespace ClassLibrary
> {
> public class Class
> {
> class MenuCmd
> {
> static int AcadVersion = Autodesk.AutoCAD.ApplicationServices.Application.Version.Major;
> // For AutoCAD 2006:
> [System.Security.SuppressUnmanagedCodeSecurity]
> [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "acedMenuCmd")]
> extern private static int acedMenuCmd16(string cmd);
> // For AutoCAD 2007:
> [System.Security.SuppressUnmanagedCodeSecurity]
> [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "acedMenuCmd")]
> extern private static int acedMenuCmd17(string cmd);
> public static int acedMenuCmd(string cmd)
> {
> switch (AcadVersion)
> {
> case 16: return acedMenuCmd16 (cmd);
> case 17: return acedMenuCmd17 (cmd);
> }
> return -1;
> }
> };
>
> [CommandMethod("TESTMENU")]
> static public void test() // This method can have any name
> {
> MenuCmd.acedMenuCmd("p0=ACAD.OSNAP");
> MenuCmd.acedMenuCmd("p0=*");
> }
> }
> }
> [/code]
Thanks Alexander
what you provided worked like a charm. Took me awhile though to figure
out how to "grey" a menu item. Not used to cui files yet, was using the
wrong "ID's". Works good now though 🙂
Can I access any Acad command the same way?
Perry