0

I am wanting to add buttons to certain contextual ribbons...  Specifically:

Modify | Multi-Select, Modify | Pipes, Modify | Sprinklers, Modify | Pipe Accessories, Modify | Pipe Fittings, Modify | Mechanical Equipment and Modify | Generic Models   and place the buttons within a panel of my creation.  How can I accomplish this? 

I've tried:

if (pTab.Id == "Modify | Pipes")
{
    foreach (var pPanel in pTab.Panels)
    {
        if (pPanel.Source.Id == "Edit") //Also tried edit_shr
        {// Add button.
            pIcon = Properties.Resources.AS_Revit_UI_hydraulicParameters_icon.GetHbitmap();
            var pBtn = new Autodesk.Windows.RibbonButton()
            {
                Name = "Hydraulic Parameters",
                Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(pIcon, IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(32, 32)),
                Id = "id_hydParam",
                AllowInStatusBar = true,
                AllowInToolBar = true,
                GroupLocation = Autodesk.Private.Windows.RibbonItemGroupLocation.Middle,
                MinHeight = 0,
                MinWidth = 0,
                Height = 32,
                Width = 32,
                IsEnabled = true,
                IsVisible = true,
                IsCheckable = true,
                ShowImage = true,
                ShowText = true,
                Orientation = System.Windows.Controls.Orientation.Vertical,
                Text = "Hydraulic Parameters",
                Size = Autodesk.Windows.RibbonItemSize.Large,
                ResizeStyle = Autodesk.Windows.RibbonItemResizeStyles.HideText
            };

            pPanel.Source.Items.Add(pBtn);
            //Add event handler for button push
        }
    }
}

That, unfortunately, didn't work.  I'm sure this is possible - I just don't know how.  I feel like it's a matter of not know the Revit-issued tab names - like Modify | Pipes is really something like modify_pipes or something like that.      The code above was me trying to put my button in a Revit panel...  Is there a way to add my own panel with my own buttons?  Something like this:  

enter image description here

That's the ideal situation.  I'm more than comfortable with any other solutions like adding the buttons to existing panels.  Any help is good help!  Thanks!!

Uchiha Itachi
  • 1,251
  • 1
  • 16
  • 42

1 Answers1

2

This can indeed be achieved in the following way:

  • Create a ribbon panel button in the normal way, anywhere you like, in one of the default locations.
  • Move the button to some other location using the .NET Automation API.

If your target location is a contextual tab, you may have to relocate your button every time the tab is opened.

This process is documented by The Building Coder:

http://thebuildingcoder.typepad.com/blog/2014/07/moving-an-external-command-button-within-the-ribbon.html

This is not recommended for production use, and I have heard reports that this approach may lead to crashes and file corruption, so beware!

Please note the Disclaimer!

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Well if that's the case, then we're not doing it... Thanks Jeremy!! You're a huge help as usual. – Uchiha Itachi Mar 16 '17 at 13:58
  • Do you know of a way to add a custom panel to the `Modify` tab? We already add buttons to it, but a whole panel would be nice and classy... – Uchiha Itachi Mar 16 '17 at 15:50
  • 1
    i think the same thing applies: create your panel as normal using the Revit API, and then move it to the desired location using .NET Automation. – Jeremy Tammik Mar 17 '17 at 07:56
  • @JeremyTammik So, can we not hide buttons on different modify tabs? – SCramphorn Apr 23 '19 at 09:30
  • The Revit API enables you to enable and disable buttons using the command availability class. I do not believe it support hiding them. You may be able to implement that using the .NET Automation library functionality. – Jeremy Tammik Apr 24 '19 at 10:10
  • Here is a way to [add a custom button to the Modify tab](https://thebuildingcoder.typepad.com/blog/2014/06/room-editor-live-and-unofficial-custom-ribbon-button.html#4). However, test it carefully and deploy with great care, since there it has been rumoured that this approach may cause instability and crash Revit! – Jeremy Tammik Apr 24 '19 at 10:12