Not able to retrieve PushButtonData name

Not able to retrieve PushButtonData name

lrsmns
Enthusiast Enthusiast
236 Views
3 Replies
Message 1 of 4

Not able to retrieve PushButtonData name

lrsmns
Enthusiast
Enthusiast

Hi,

so i have this method where i create multiple buttons with the same command but different naming as the parameter:

 

public static void AddButtonsToPanel(RibbonPanel panel, List<(string name, string labelText, string IconPath, string ToolTip)> buttons, string commandClassName)
{
    var assembly = Assembly.GetExecutingAssembly();

    foreach (var button in buttons)
    {
        var buttonData = new PushButtonData(button.name, button.labelText, assembly.Location, commandClassName)
        {
            ToolTip = button.ToolTip,
            LargeImage = ImageUtility.LoadImage(assembly, button.IconPath)
        };

        panel.AddItem(buttonData);
    }
}
var toolTip = "";
var familyKategorien = new List<(string Name, string Text, string IconPath, string ToolTip)>
{
    ("IT - Ausstattung", "IT\nAusstattung", "IT.png", toolTip),
    ("Tische", "Tische", "Tische.png", toolTip)
};
ButtonUtilities.AddButtonsToPanel(panel, familyKategorien, "familyCmd");
#endregion

 

 

and i try to get the button's name through the component manager:

 

private void ComponentManager_PreviewExecute(object sender, EventArgs e)
{
    var buttonCaller = sender as Autodesk.Windows.RibbonButton;
    if (buttonCaller != null)
    {
        Autodesk.Revit.UI.TaskDialog.Show("Debug",
                $"Button Properties:\n" +
                $"Name: {buttonCaller.Name}\n" +
                $"Text: {buttonCaller.Text}\n" +
                $"Id: {buttonCaller.Id}");

        Familien.Kategorie = buttonCaller.Name; // Assign Name to Kategorie

        if (string.IsNullOrEmpty(Familien.Kategorie))
        {
            Autodesk.Revit.UI.TaskDialog.Show("Debug", "Familien.Kategorie is empty!");
        }
        Familien.Kategorie = buttonCaller.Name;
    }
}

 

However the result was null for everything except the text, shown in this pic:

lrsmns_0-1733930760167.png

 

 

Any insights or hints would be very appreciated!

0 Likes
237 Views
3 Replies
Replies (3)
Message 2 of 4

Sean_Page
Collaborator
Collaborator

You may need to look for the buttonCaller.AutomationName

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 3 of 4

lrsmns
Enthusiast
Enthusiast

I tried it and it's still returning the Text value and not from Name

lrsmns_0-1733993525036.png

 

0 Likes
Message 4 of 4

Sean_Page
Collaborator
Collaborator

Could you try casting to a RibbonItem vs RibbonButton and then use item.Source.Name?

 

Not exactly the same, but here is how I get or use buttons by name from the ribbon.

 

foreach(Autodesk.Windows.RibbonTab tab in Autodesk.Windows.ComponentManager.Ribbon.Tabs)
{
    if(tab.Name == SomeTabName)
    {
        foreach(Autodesk.Windows.RibbonPanel panel in tab.Panels)
        {
            if(panel.Source.Name.Equals(panelName, System.StringComparison.CurrentCultureIgnoreCase))
            {
                foreach(Autodesk.Windows.RibbonItem item in panel.Source.Items)
                {
                    if(item.AutomationName == buttonName)
                    {
                        {
                            //Do something here
                        }
                    }
                }
            }
        }
    }
}

 

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes