Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to add buttons to contextual ribbons

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
2421 Views, 5 Replies

How to add buttons to contextual ribbons

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:

 

ContextualRibbonPanel.png

 

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!!

5 REPLIES 5
Message 2 of 6
matthew_taylor
in reply to: Anonymous

Hi,
Check out this link:
https://forums.autodesk.com/t5/revit-api-forum/how-to-check-the-exisiting-of-ribbon-tab-and-ribbon-p...
That should help you cycle through and find anything you need.
You may need to create the panel/buttons (using the api) on a legitimate Revit tab that is easily accessible and move/copy them to the contextual tab (using Autodesk.windows functions).

Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 3 of 6
Anonymous
in reply to: matthew_taylor

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.

 

Message 4 of 6
matthew_taylor
in reply to: Anonymous

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.


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 5 of 6
Anonymous
in reply to: matthew_taylor

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.

Message 6 of 6
matthew_taylor
in reply to: Anonymous

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.


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report