如何在Revit功能区面板中堆叠按钮(网格布局)

时间:2017-03-20 19:45:52

标签: c# ribbon revit-api

我已经创建了一个自定义面板,我已将其放置在Revit php -S localhost:8000标签中。目前,按钮严格水平放置。我想以网格格式(行和列)堆叠它们。有没有人知道访问布局属性的方法或任何其他方法来实现这个?

enter image description here

代码:

Modify

2 个答案:

答案 0 :(得分:3)

是。当您调用命令将RibbonItem添加到面板时,您应该调用RibbonPanel.AddStackedItems();。您可以传入两个或三个,它会将它们堆叠成一个“列”。

答案 1 :(得分:0)

所以,经过一番挣扎,我解决了我的问题(对Mike和Jeremy提出了一些有用的建议^^)。如果您想在这样的网格布局中将自己的功能区面板添加到Revit 修改选项卡,它有点工作,但完全值得!

enter image description here

首先,创建一个函数以将Panel添加到选项卡:

public Autodesk.Windows.RibbonPanel CreateCustomPanel()
{
    string sPanel = "Panel Name";
    IntPtr pIcon;

    var pSource = new Autodesk.Windows.RibbonPanelSource()
    {
        Title = sPanel, 
        Id = "id_name", 
        IsSlideOutPanelVisible = true, 
        Description = null,
        DialogLauncher = null, 
        UID = null, 
        Tag = null, 
        Name = null,
    };

    var pRow1Source = new Autodesk.Windows.RibbonSubPanelSource()
    {
        Description = null, Id = "row1_shr", Name = null, Tag = null, UID = null
    };
    var pRow2Source = new Autodesk.Windows.RibbonSubPanelSource()
    {
        Description = null, Id = "row2_shr", Name = null, Tag = null, UID = null
    };

    var hPanel = new Autodesk.Windows.RibbonPanel()
    {
        Source = pSource, IsVisible = true, IsEnabled = true
    };

    var hPanelRow1 = new Autodesk.Windows.RibbonRowPanel()
    {
        Height = 32, Id = "pRow1", IsEnabled = true, IsVisible = true, Source = pRow1Source
    };

    var hPanelRow2 = new Autodesk.Windows.RibbonRowPanel()
    {
        Height = 32, Id = "pRow1", IsEnabled = true, IsVisible = true, Source = pRow2Source
    };

    Autodesk.Windows.RibbonSeparator pBreak = new Autodesk.Windows.RibbonSeparator();
    pBreak.SeparatorStyle = Autodesk.Windows.RibbonSeparatorStyle.Invisible;

    string sBtnText;
    // Add buttons to Row 1
    pIcon = Properties.Resources.YourResourceName.GetHBitmap();
    sBtnText = "Button Text";
    var pPanelBtn = new Autodesk.Windows.RibbonButton()
    {
        //SET BUTTON PROPERTIES HERE
    };
    Autodesk.Windows.ComponentManager.UIElementActivated += BtnEventHandler;
    hPanelRow1.Source.Items.Add(pPanelBtn);
    hPanelRow1.Source.Items.Add(pBreak);

    //Repeat for more buttons
    hPanel.Source.Items.Add(hPanelRow1);
    hPanel.Source.Items.Add(new Autodesk.Windows.RibbonRowBreak());
    //Repeat for second row
    hPanel.Source.Items.Add(hPanelRow2);

    return hPanel;
}

然后,它就像:

一样简单
Autodesk.Windows.RibbonControl pRibbon = Autodesk.Windows.ComponentManager.Ribbon;
foreach (var pTab in pRibbon.Tabs)
{
    if (pTab.Id == "Modify")
    {
        pTab.Panels.Add(CreateCustomPanel());
        break;
    }
}