We are developing a plugin for Revit 2015 and trying to hide certain buttons from our custom RibbonTab depending on the type of open document. For that we intended to create an event handler that checks ViewActivated event. Firstly can we even use this event to differentiate between family view and model view? Secondly if we can indeed use this event, where should be the correct place to create the EventHandler?
You can register for these kinds of events in either UIControlledApplication or UIApplication.
You can differentiate between family documents and project documents using the Document.IsFamilyDocument property, the parameters passed to your event handlers should give you a path to the active document.
Hi raunoveb,
what about an availability class ?
TBC says:
"To disable and hide your button, you can make use of an availability class, i.e. a class implementing the IExternalCommandAvailability interface and the PushButton.AvailabilityClassName property specifying its name:
That will allow you to toggle the visibility and availability of your class at will, just as you require."
No need to subcribe to any sort of event this way.
Best regards,
Revitalizer
Hmm, I didn't know you could hide a button with IExternalCommandAvailability. I've only ever used it for enabling / disabling. Is this standard functionality or are you simply using the IsCommandAvailable method to call other code that hides the button?
We already made use of the IExternalCommandAvailability interface and it properly enables/disables these buttons but what we'd also like to do is to hide this button. How can we get the reference to the button inside IsCommandAvailable method?
Dear Scott,
yes, of course, with this availability class, you can only enable or disable buttons.
Changing the visibility at runtime is also possible since each RibbonItem has a Visible property.
This could be used to fill comboboxes or pulldownbuttons with a changing list of displayed items:
http://forums.autodesk.com/t5/revit-api/ribbon-combobox-clear-change-data/td-p/5061392
If one really wants to hide buttons, he has to subcribe to ViewActivated event and perform the steps you've already suggested.
Best regards,
Revitalizer
Dear raunoveb,
you could either make you buttons global static variables, so you can access them from everywhere.
Or you can browse Ribbon structure by using UIControlledApplication.GetRibbonPanels(tabName).
Then browse each RibbonPanel for the button you need, either by its name or its text.
Best regards,
Revitalizer
Yeah, thanks. I already used this solution. I just hoped there would be a more intelligent way to achieve this. Unfortunately there isn't.