Use IExternalCommandAvailability on PullDownButton

Use IExternalCommandAvailability on PullDownButton

m.de.vriesTH5VM
Enthusiast Enthusiast
374 Views
1 Reply
Message 1 of 2

Use IExternalCommandAvailability on PullDownButton

m.de.vriesTH5VM
Enthusiast
Enthusiast

There currently is no way to use the IExternalCommandAvailability interface to enable/disable pulldown buttons.

The necessary property AvailabilityClassName only exists for PushButton and Button classes.

This makes some sense as the PullDownButton itself does not implement an external command, so the menu would not know where to look for the class instance for the interface that it must call to check availability.

 

In my menu I have a couple of PullDownButtons that contains command buttons that only are applicable when Revit is in a family document, and also a couple that have command buttons that only apply when Revit is not in a family editor.

 

Is there another way to implement something like the IExternalCommandAvailability interface specifically for PullDownButtons, or will I have to rely on using an Idle event for this?

0 Likes
Accepted solutions (1)
375 Views
1 Reply
Reply (1)
Message 2 of 2

ricaun
Advisor
Advisor
Accepted solution

As you explain, IExternalCommandAvailability interface is for PushButton or objects that execute the interface IExternalCommand.

 

You probably could create some to enable/disable the PullDownButton using the Idling event, and I don't think that is worth doing that.

 

Why are you not applying the same IExternalCommandAvailability interface in all the PushButton inside the PullDownButton?

 

Here is what happens when all the buttons are not available in PullDownButton and SplitButton.

 

Forum - 2023-11-09 10-17-02.gif

 

All Buttons are the same IExternalCommand and IExternalCommandAvailability.

 

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Threading.Tasks;

namespace RevitAddin.Forum.Revit.Commands
{
    [Transaction(TransactionMode.Manual)]
    public class CommandSwapAvailable : IExternalCommand, IExternalCommandAvailability
    {
        public static bool IsAvailable { get; set; } = true;
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            IsAvailable = !IsAvailable;
            Task.Run(async () =>
            {
                await Task.Delay(2000);
                IsAvailable = !IsAvailable;
            });
            return Result.Succeeded;
        }

        public bool IsCommandAvailable(UIApplication uiapp, CategorySet categorySet)
        {
            return IsAvailable;
        }
    }
}

 

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils