using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Reflection;
using System.Resources;
namespace PSM_Plugin
{
public class MyCommands
{
[CommandMethod("PSM_LIST_COMMANDS")]
public void PSM_LIST_COMMANDS()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
Assembly assembly = Assembly.GetExecutingAssembly();
Type[] types = assembly.GetTypes();
ResourceManager RM = new ResourceManager(this.GetType());
foreach (Type type in types)
{
// Проходим по всем классам этой сборки
MethodInfo[] mis = type.GetMethods();
foreach (MethodInfo mi in mis)
{
// Проходим по методам класса.
// Смотрим есть ли атрибут команды у метода
object[] atts = mi.GetCustomAttributes(typeof(CommandMethodAttribute), true);
if (mi.IsPublic && atts.Length > 0)
{
CommandMethodAttribute ca = ((CommandMethodAttribute)atts[0]);
// Получаем глобальное и локальное имя команды
string commandNameGlobal = ca.GlobalName;
string commandNameLocal = commandNameGlobal;
if (ca.LocalizedNameId != null)
{
try { commandNameLocal = RM.GetString(ca.LocalizedNameId); } catch { };
}
ed.WriteMessage("\n{0} {1}", commandNameGlobal, commandNameLocal);
}
}
}
}
// Тестовая команда 1 - только для проверки
[CommandMethod("PSM_COMMAND1")]
public void PSM_COMMAND1()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
ed.WriteMessage("\nPSM_COMMAND1");
}
// Тестовая команда 2 - только для проверки
[CommandMethod("PSM","PSM_COMMAND2", "PSM_COMMAND2",CommandFlags.Modal)]
public void PSM_COMMAND2()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
ed.WriteMessage("\nPSM_COMMAND2");
}
}
}