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
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:
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!!
Solved! Go to Solution.
Solved by matthew_taylor. Go to Solution.
Thanks Matt. I'll take a look and let you know if that works for me.
EDIT:
Sorry Matt - that's not quite what I'm looking for. I'm not concerned with what's in a Ribbon Panel currently. I'm more focused on how to edit existing Revit contextual panels - specifically the ones I mentioned.
Hi @Anonymous,
You're right. I couldn't browse code last night, and the functions aren't as good as I remember them.
I've managed to get actual contextual panels running. I've used a combination of AdWindows, some ribbon extension methods (that I think I got from RedBolts aeons ago), and IExternalCommandAvailability. Zip file of solution attached.
The AdWindows techniques aren't supported by Autodesk.
There's no error checking etc, it's just a 'proof of concept'.
To run:
After the app had loaded, start a project.
Check the 'Modify' tab - nothing new is shown.
Select a single titleblock family instance.
(Make the contextual tab show if your settings don't make that happen already.)
Voila, new button and panel. It looks exactly like a contextual panel.
Click the new button - it should tell you about your titleblock.
Deselect the titleblock, and click on the Modify tab - the extra panel should vacate. You can probably see it hide, it's a tiny bit laggy.
Neat.
Thanks Matt!
Jeremy actually replied to my post on StackOverflow and said that essentially that you can add a button to the contextual menus, but it can cause crashes and file corruptions. Since we obviously don't want that, I'm now attempting to simply add a custom panel to the Modify tab next to the Create panel. We've added buttons to it in the past with little problems. Hopefully adding a whole panel doesn't give me too much trouble.
Also, I couldn't open your code attachment for some reason. My VS can be a bit testy I suppose. I appreciate your help.
Hi @Anonymous,
Actually, my solution is just adding a button to the Modify tab...but they actually go in the contextual area that you want.
I've used the adwin methods extensively (for hundreds of users, over versions 2011-2017) and haven't seen any issues at all. You may even be able to eliminate their usage if you can natively add to the Modify tab (I haven't tried).
My solution was produced using Visual Studio 2013 Pro Update5, and zipped using winzip.
Can't find what you're looking for? Ask the community or share your knowledge.