[assembly: CommandClass(typeof($safeprojectname$.AcadCmds))]
[assembly: ExtensionApplication(typeof($safeprojectname$.AcadCmds))]
namespace $safeprojectname$;
public class AcadCmds : IExtensionApplication
{
public void Initialize()
{
// 如果需要将程序的目录加入信任路径,将下行代码取消注释
// AppendSupportPath(CurrentDirectory.FullName);
}
public void Terminate()
{
// 这里不能调用输出函数,因为这个函数执行的时候,已经没有editor对象了。
// 所以如果不是想要在cad关闭的时候清理某些东西,这里不用写任何的代码。
}
/// <summary>
/// 查看所有功能命令-See Command
/// </summary>
[Description("查看所有功能命令-See All Command")]
[CommandMethod(nameof(SACMD), CommandFlags.Session | CommandFlags.UsePickSet)]
public void SACMD()
{
var type = typeof(AcadCmds);
// 仅获取自己编写的方法
var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
foreach (MethodInfo method in methods)
{
if (method != null)
{
var attributes = method.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attributes.Length > 0)
{
var descAttr = attributes[0] as DescriptionAttribute;
Acap.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\n{method.Name};{descAttr?.Description}");
}
}
}
}
/// <summary>
/// Your Command Description
/// </summary>
[Description("Your Command Description")]
[CommandMethod(nameof(YourCommand), CommandFlags.Session | CommandFlags.UsePickSet)]
public void YourCommand()
{
//Your Codes
}
}
GlobalUsing.cs内容:
#region System Using
global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Text;
global using System.Threading.Tasks;
global using System.ComponentModel;
global using System.Reflection;
#endregion System Using
#region AutoCAD Using
global using Autodesk.AutoCAD.Runtime;
global using Autodesk.AutoCAD.EditorInput;
global using Autodesk.AutoCAD.DatabaseServices;
global using Acap = Autodesk.AutoCAD.ApplicationServices.Application;
global using Acaop = Autodesk.AutoCAD.ApplicationServices.Core.Application;
#endregion AutoCAD Using