How to enable/disable circular referenced buttons in Add-in? (Converted from COM registered)

620
0
03-10-2019 07:07 PM
MarkMindlin
Occasional Contributor III

Hi,

We have to convert two COM registered command buttons to Add-in buttons.

When any button clicked, a message appears and both buttons should be disabled.

It worked "anonymously" in COM.  In "COM" code we have 

private static void DisableButtons(string progId, bool isEnabled)
{

UID pUID = new UID();
pUID.Value = progId;
ICommandItem pItem = ArcMap.Application.Document.CommandBars.Find(pUID, false, false);
IComponentAvailable pAvailable = pItem.Command as FirstButton.IComponentAvailable;
pAvailable.IsEnabled = isEnabled;

}

In "Add-in" code we need to have AddIn.FromID() method

public static class AddIn
{
   public static T FromID<T>(string id) where T : class;

}

e.g. 

AddIn.FromID<FirstButtonClass>(progId);

which means we must explicitly use reference to a Class Name (FirstButtonClass, SecondButtonClass). It will create a circular reference and will not work on Bamboo deployment (However, it builds ok on a local machine)

case "Test_FirstButton":
   pAvailable = AddIn.FromID<FirstButtonClass>(progId);
break;

case "Test_SecondButton":
   pAvailable = AddIn.FromID<SecondButtonClass>(progId); // WE SHOULD NOT USE "SecondButtonClass" here. It will raise circular dependency error on aBamboo deployment
break;

Question: can we use another ArcObjects API to disable buttons?

We cannot change the architecture. Each button exists in its own .Net solution. See the attached simple projects.

C#, ArcObjects 10.6.1 

0 Kudos
0 Replies