using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Internal;
[assembly: ExtensionApplication(typeof(UndefCommand.MyPlugin))]
namespace UndefCommand
{
public class MyPlugin : IExtensionApplication
{
string[] cmd_undef_main_list = new string[] {
"LINE",
"PLINE",
"ARC",
"SPLINE"
};
void IExtensionApplication.Initialize()
{
foreach (string cmd in cmd_undef_main_list) {
if (Utils.IsCommandDefined(cmd))
{
string cmdLocal = GetCName("_" + cmd);
Utils.RemoveCommand("ACAD_MAIN", cmdLocal);
if (cmdLocal != cmd) Utils.RemoveCommand("ACAD_MAIN", cmd);
}
}
}
void IExtensionApplication.Terminate()
{
}
#region PInvoke
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode,
EntryPoint = "?acedGetCName@@YAHPB_WPAPA_W@Z")]
private extern static Int32 acedGetCName32R18(string Name, out IntPtr otherName);
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode,
EntryPoint = "?acedGetCName@@YAHPEB_WPEAPEA_W@Z")]
private extern static Int32 acedGetCName64R18(string Name, out IntPtr otherName);
[DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode,
EntryPoint = "?acedGetCName@@YAHPB_WPAPA_W@Z")]
private extern static Int32 acedGetCName32R19(string Name, out IntPtr otherName);
[DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode,
EntryPoint = "?acedGetCName@@YAHPEB_WPEAPEA_W@Z")]
private extern static Int32 acedGetCName64R19(string Name, out IntPtr otherName);
private static string GetCName(string Name)
{
IntPtr ptr = IntPtr.Zero;
if (Application.Version.Major > 18)
{
if (IntPtr.Size == 4) acedGetCName32R19(Name, out ptr);
else acedGetCName64R19(Name, out ptr);
}
else
{
if (IntPtr.Size == 4) acedGetCName32R18(Name, out ptr);
else acedGetCName64R18(Name, out ptr);
}
return Marshal.PtrToStringUni(ptr);
}
#endregion
}
}