How to stop initializing my .net plugin

How to stop initializing my .net plugin

Anonymous
Not applicable
927 Views
4 Replies
Message 1 of 5

How to stop initializing my .net plugin

Anonymous
Not applicable

Hi,

in my IExtensionApplication instance I need to stop loading the plugin for certain conditions. What I would like to achieve is that the commands from my dll are not getting defined/can not be used.

 

According to this blog post I should be able to achieve this by throwing an exception in my IExtensionApplication instance. But this is not working, even when I throw that exception the commands are defined (AutoCAD 2021).

 

Is there another way?

0 Likes
Accepted solutions (1)
928 Views
4 Replies
Replies (4)
Message 2 of 5

ActivistInvestor
Mentor
Mentor

I prefer calling a method that tests a variable at the start of each command and returning if the condition to fail is met (after displaying a helpful message). That way, the user sees a message explaining why the command is not available, as opposed to just "Unknown command", which is likely to trigger a request for support.

 


@Anonymous wrote:

Hi,

in my IExtensionApplication instance I need to stop loading the plugin for certain conditions. What I would like to achieve is that the commands from my dll are not getting defined/can not be used.

 

According to this blog post I should be able to achieve this by throwing an exception in my IExtensionApplication instance. But this is not working, even when I throw that exception the commands are defined (AutoCAD 2021).

 

Is there another way?




0 Likes
Message 3 of 5

Anonymous
Not applicable

Thanks this is what I do now. But the requirement is to not to load the commands. So users can not see what commands are available.

0 Likes
Message 4 of 5

Alexander.Rivilis
Mentor
Mentor
Accepted solution

@Anonymous 

In this case you have not define command with CommandMethod attribute, but define with help of Autodesk.AutoCAD.Internal.Utils.AddCommand(string cmdGroupName, string cmdGlobalName, string cmdLocalName, CommandFlags cmdFlags, CommandCallback func) method in your IExtensionApplication.Initialize method only if you condition allowed it.

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Internal;
 
// This line is not mandatory, but improves loading performances
[assembly: ExtensionApplication(typeof(CommandUtils.MyPlugin))]
 
namespace CommandUtils
{
  public class MyPlugin : IExtensionApplication
  {
    static bool condition = false;
    void IExtensionApplication.Initialize()
    {
      
      if (condition)
      {
         Utils.AddCommand("RIVILIS", "TEST1", "ТЕСТ1", CommandFlags.Modal, CommandHandler1);
         Utils.AddCommand("RIVILIS", "TEST2", "ТЕСТ2", CommandFlags.Modal, CommandHandler2);
      }
    }
 
    void IExtensionApplication.Terminate()
    {
      if (condition)
      {
	 Utils.RemoveCommand("RIVILIS", "TEST1");
	 Utils.RemoveCommand("RIVILIS", "TEST2");
      }
    }
    public void CommandHandler1()
    {
      Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
      ed.WriteMessage("\nCommand Test1");
    }
    public void CommandHandler2()
    {
      Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
      ed.WriteMessage("\nCommand Test2");
    }
  }
}

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 5 of 5

Anonymous
Not applicable

@Alexander.Rivilisawesome, exactly what I need, thank you

0 Likes