Revit API 中带有图像和空字符串的按钮

问题描述 投票:0回答:3

我正在 Revit 中创建一个带有一些堆叠按钮的新选项卡。我需要放置一个没有文本的按钮,例如附图: image of buttons without text.

我正在使用以下代码:

RibbonPanel panelMenu6 = application.CreateRibbonPanel(tabName, panelNameMenu6);

//create large buttons
PushButtonData Button23 = new PushButtonData("Button 23", "Button 23", directoryName + @"\pyRevit.dll", "pyRevit.TheCommand");
PushButton button23 = panelMenu6.AddItem(Button23) as PushButton;
button23.LargeImage = new BitmapImage(new Uri(directoryName + "\\Icons Resources\\Button 17 -bulleted-list-16 (2).png"));

//create small buttons
PushButtonData Button24 = new PushButtonData("Button 24", "Button 24", directoryName + @"\pyRevit.dll", "pyRevit.TheCommand");
Button24.Image = new BitmapImage(new Uri(directoryName + "\\Icons Resources\\Button 23 -address-16 (2).png"));

PushButtonData Button25 = new PushButtonData("Button 25", "Button 25", directoryName + @"\pyRevit.dll", "pyRevit.TheCommand");
Button25.Image = new BitmapImage(new Uri(directoryName + "\\Icons Resources\\Button 24 -paint-palette-16 (2).png"));
panelMenu6.AddStackedItems(Button24, Button25);

我尝试发送一个空字符串而不是“按钮 25”,但收到异常“该值不能为空。参数名称:文本”。

这是我收到错误时的代码。例如,没有文本的按钮 24:

PushButtonData Button24 = new PushButtonData("Button 24", **""**, directoryName + @"\pyRevit.dll", "pyRevit.TheCommand");

我尝试创建一个按钮,如附图 1 中的按钮。仅图像,无文本

c# revit-api
3个回答
1
投票

感谢这个博客我能够创建没有文本的按钮。这是代码

using AW = Autodesk.Windows;
/// <summary>
    /// Each item shall be converted into Autodesk windows item
    /// </summary>
    /// <param name="tabName"></param>
    /// <param name="panelName"></param>
    /// <param name="itemName"></param>
    /// <returns></returns>
    public AW.RibbonItem GetButton(string tabName, string panelName, string itemName)
    {
        AW.RibbonControl ribbon = AW.ComponentManager.Ribbon;
        foreach (AW.RibbonTab tab in ribbon.Tabs)
        {
            if (tab.Name == tabName)
            {
                foreach (AW.RibbonPanel panel in tab.Panels)
                {
                    if (panel.Source.Title == panelName)
                    {
                        return panel.FindItem("CustomCtrl_%CustomCtrl_%"
                          + tabName + "%" + panelName + "%" + itemName,
                          true) as AW.RibbonItem;
                    }
                }
            }
        }
        return null;
    }
    /// <summary>
    /// A List contains items which shall be without text
    /// after converting each item to autodesk windows item using getbutton method
    /// set the text display to false
    /// and set the size to large
    /// </summary>
    /// <param name="ribbonItem"></param>
    /// <param name="tabName"></param>
    /// <param name="panelName"></param>
    public void editNoTextButtons(IList<RibbonItem> ribbonItem, string tabName, string panelName)
    {
        foreach (var item in ribbonItem)
        {
            var adwinbutton = GetButton(tabName, panelName, item.Name);
            adwinbutton.ShowText = false;
            adwinbutton.Size = Autodesk.Windows.RibbonItemSize.Large;

        }
    }

And that's how it looks like


0
投票

最佳实践是为按钮指定适当的名称。仅当 Revit 窗口大小调整得小于允许显示的按钮名称时,Revit 界面才会像您发送的图像一样显示。


0
投票
PushButtonData lvdcButtonData = new PushButtonData("LVDC", "\u200B", thisAssemblyPath, "LVDC.VDCFile");

“\u200B”是零宽度空格字符的 Unicode 表示形式。它在 UI 中不可见,有效隐藏文本,同时仍然满足 ItemText 属性具有非空字符串的要求。

这对我来说很有效。

© www.soinside.com 2019 - 2024. All rights reserved.