So I was asked the other day how to execute “Extract component” command found on the feature tree context menu in a VC 4.0 .NET API plugin. I said the answer is simple. Simply do this in your plugin.
var cmd = IoC.Get<ICommandRegistry>();
var extractCmd = cmd.FindItem(“ExtractComponentCommand”);
extractCmd.Execute();
Ok good but how did you know the command Id? Well I simply went through the command registry and display the UI name against the Id.
var cmds = IoC.Get<ICommandRegistry>().Actions;
List<string> cmdsList = new List<string>();
foreach (IActionItem cmd in cmds)
{
cmdsList.Add(cmd.Content + ": " + cmd.Id);
}
var sort = from s in cmdsList
orderby s ascending
select s;
foreach (string cmdList in sort)
{
IoC.Get<IMessageService>().AppendMessage(cmdList, MessageLevel.Warning);
}
Well, it’s that simple.