Revit Addin OnStartUp Confusion - How to Disable Panels based on Entitlements?

Revit Addin OnStartUp Confusion - How to Disable Panels based on Entitlements?

Anonymous
Not applicable
913 Views
2 Replies
Message 1 of 3

Revit Addin OnStartUp Confusion - How to Disable Panels based on Entitlements?

Anonymous
Not applicable

I'm trying to check whether someone should be able to use my addin based on the entitlement API. But I'm not sure how to pass a variable between an event handler and a class.

private Boolean Purchased = false;
public Result OnStartup(UIControlledApplication application)
    {
            AddRibbonPanel(application);
            application.ControlledApplication.ApplicationInitialized += ControlledApplication_ApplicationInitialized;

            Autodesk.Windows.RibbonControl ribbon = Autodesk.Windows.ComponentManager.Ribbon;
            foreach (Autodesk.Windows.RibbonTab tab in ribbon.Tabs)
            {
                if (tab.Name == "MyTab")
                {
                    foreach (Autodesk.Windows.RibbonPanel panel in tab.Panels)
                    {
                        panel.IsEnabled = this.Purchased;
                    }
                }
            }
                // end of entitlement api status check
                return Result.Succeeded;
        }

The event handler in line 5 check the REST resonse and sets 'Purchased' to true, but it doesn't seem to execute before for each loop. Is there a way to force the event to trigger first? Or what effective strategies can we use to enable/disable our plugins based in the EntitlementAPI?

 

thanks in advance

 

0 Likes
Accepted solutions (1)
914 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Jonah,

 

Thank you for your query.

 

Yes, indeed, there is no way for you to guarantee that the REST call will be executed synchronously.

 

I would suggest executing it in an asynchronous context, and using another method to enable and disable your add-in functionality.

 

For instance, you could use the IExternalCommandAvailability interface at a later point, after start-up:

 

https://apidocs.co/apps/revit/2019/c05acaf4-4cd9-8fd6-db06-44b22ae4f987.htm

 

Here is one sample making use of a trivial command availability class:

 

http://thebuildingcoder.typepad.com/blog/2012/11/roll-your-own-toggle-button.html

 

I hope this helps.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 3

Anonymous
Not applicable

Thank you so much Jeremy. I ended up having the buttons initiate as disabled and having a button that checks entitlements and enables the other buttons. It's not as automatic as checking on start up, but it is fine compromise. The toggle-button code was really helpful.

0 Likes