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

huangapple go评论55阅读模式
英文:

Button with image and empty string in Revit API

问题

I am creating a new tab with some stacked buttons in revit. I need to place a button without text such as the attached image:
Revit API 中的带图像和空字符串的按钮.

I am using the following code:

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", "", 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);

I tried to send an empty string instead of "Button 25" but I receive an exception "The value cannot be empty. Parameter name: text."

That's the code when I receive the error. For instance, Button 24 without text:

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

I try to create a pushbutton such as those in the attached pic 1. Image only and no text

英文:

I am creating a new tab with some stacked buttons in revit. I need to place a button without text such as the attached image:
Revit API 中的带图像和空字符串的按钮.

I am using the following code:

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);

I tried to send an empty string instead of "button 25" but I receive an exception "The value cannot be empty. Parameter name: text".

That's the code when I receive the error. For instance, Button 24 without text:

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

I try to create a pushbutton such as those in the attached pic 1. Image only and no text

答案1

得分: 0

最佳做法是为推按钮分配一个合适的名称。仅当 Revit 窗口缩小到不允许按钮名称出现时,Revit 界面才会显示像您发送的图像一样。

英文:

Best practice would be to assign an appropriate name for the pushbutton. The Revit interface only displays like the image you sent when the Revit window has been resized smaller than allows for button names to appear.

答案2

得分: 0

以下是您提供的代码的中文翻译:

感谢这个博客,我能够创建没有文本的按钮。以下是代码示例:

using AW = Autodesk.Windows;

/// <summary>
/// 将每个项目转换为 Autodesk Windows 项目
/// </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>
/// 包含无文本项的列表
/// 在使用 getbutton 方法将每个项目转换为 Autodesk Windows 项目之后
/// 将文本显示设置为 false
/// 并将大小设置为大
/// </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;
    }
}

这是效果

英文:

Thanks to this blog I was able to create buttons without text. here is the code

using AW = Autodesk.Windows;
/// &lt;summary&gt;
    /// Each item shall be converted into Autodesk windows item
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;tabName&quot;&gt;&lt;/param&gt;
    /// &lt;param name=&quot;panelName&quot;&gt;&lt;/param&gt;
    /// &lt;param name=&quot;itemName&quot;&gt;&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    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(&quot;CustomCtrl_%CustomCtrl_%&quot;
                          + tabName + &quot;%&quot; + panelName + &quot;%&quot; + itemName,
                          true) as AW.RibbonItem;
                    }
                }
            }
        }
        return null;
    }
    /// &lt;summary&gt;
    /// 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
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;ribbonItem&quot;&gt;&lt;/param&gt;
    /// &lt;param name=&quot;tabName&quot;&gt;&lt;/param&gt;
    /// &lt;param name=&quot;panelName&quot;&gt;&lt;/param&gt;
    public void editNoTextButtons(IList&lt;RibbonItem&gt; 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

huangapple
  • 本文由 发表于 2023年7月3日 12:44:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76601888.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定