Get Ribbon Button Click Event in API

Get Ribbon Button Click Event in API

Anonymous
Not applicable
5,689 Views
12 Replies
Message 1 of 13

Get Ribbon Button Click Event in API

Anonymous
Not applicable

Hi,

 

I need to find the ribbon button click event in revit API. Kindly help me to accomplish this.

 

Thanks and Regards,

Vinoth Kumar.R 

Accepted solutions (1)
5,690 Views
12 Replies
Replies (12)
Message 2 of 13

matthew_taylor
Advisor
Advisor

Hi @Anonymous,

This previous post should give you what you need:

http://forums.autodesk.com/t5/revit-api-forum/recording-executed-commands/m-p/6675159/highlight/true#M19334

 

Cheers,

 

-Matt


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?
0 Likes
Message 3 of 13

Anonymous
Not applicable

Hi Matt,

 

Thanks for the reply. I have not found the event "ItemExecuted" which was mentioned in that link for RibbonItem or RibbonButton classes which was available in Autodesk.Windows dll. Whatever we are adding to existing panels for those items we can get the click event. But for the items which are available default in Revit for those i am not able to find the click event.

 

Thanks and Regards,

Vinoth Kumar.R

0 Likes
Message 4 of 13

matthew_taylor
Advisor
Advisor

Hi Vinoth,

Here's a snippet to get you started. I actually use the UIElementActivated event:

 

Imports Autodesk.Revit.Attributes
Imports Autodesk.Revit
Imports adWin = Autodesk.Windows
<Transaction(TransactionMode.Manual)> _
<Regeneration(RegenerationOption.Manual)> _
<Journaling(JournalingMode.UsingCommandData)> _
<DisplayName("Application Name")> _
<Description("Application Description")> _
Public Class YourApp
    Implements UI.IExternalApplication
  Public Function OnStartup(ByVal a As UI.UIControlledApplication) As UI.Result Implements UI.IExternalApplication.OnStartup
                  'event handler
            AddHandler adWin.ComponentManager.UIElementActivated, AddressOf ComponentManager_UIElementActivated
      Return UI.Result.Succeeded
  End Function
  Public Function OnShutdown(ByVal a As UI.UIControlledApplication) As UI.Result Implements UI.IExternalApplication.OnShutdown
                  RemoveHandler adWin.ComponentManager.UIElementActivated, AddressOf ComponentManager_UIElementActivated
    Return UI.Result.Succeeded
  End Function
  Private Sub ComponentManager_UIElementActivated(ByVal sender As Object, ByVal e As Autodesk.Windows.UIElementActivatedEventArgs)
         'do your thing with the e
  end sub
end class

 

Let us know how you get on.

 

Cheers,

 

-Matt


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 13

Anonymous
Not applicable

Hi Matt,

 

The code you have provided does not work. Thanks for the reply.

 

Thanks and Regards,

Vinoth Kumar.R

0 Likes
Message 6 of 13

matthew_taylor
Advisor
Advisor
Accepted solution

Hi @Anonymous,

'Does not work'? You're going to have to explain better than that!

 

I can assure you that it does work. I use it myself.

Explore the e object in the ComponentManager_UIElementActivated function.

Put a break mark in there and browse the objects.

 

Cheers,

 

-Matt


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?
0 Likes
Message 7 of 13

Anonymous
Not applicable

Hi Matt,

 

The code you have provided which will work only for the items you are going to add to the RibbonPanels into Revit. But the query was different. I have to get the click events for the items which are available in Revit by Default. Please refer the attached image.

 

 

Thanks and Regards,

Vinoth Kumar.R

0 Likes
Message 8 of 13

matthew_taylor
Advisor
Advisor

@Anonymous,

You are wrong. I use it to trap all ribbon item clicks.

Such as this:

Modify > Modify > Delete (Modify tab, Modify Panel, Delete item)

 

You will need to investigate further.

 

Cheers,

 

-Matt

 

 


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?
0 Likes
Message 9 of 13

Anonymous
Not applicable

Hi Matt,

 

Apologies. Your are not wrong. 

 

Thanks and Regards,

Vinoth Kumar.R

0 Likes
Message 10 of 13

TheRealChrisHildebran
Advocate
Advocate

Matt (@matthew_taylor) , thank you for your example on monitoring UI Click Events!

 

There is a button id like to monitor which does not trigger the event. It is the Settings button in the MEP Fabrication Parts Dockable Dialog (Screenshot below). Have you found this to be true also? Ive examined the e object and looked at other members of  'Autodesk.Windows' but nothing pops out to me. 

 

Any thoughts?

MonitorUiClick.png

0 Likes
Message 11 of 13

matthew_taylor
Advisor
Advisor

Hello @TheRealChrisHildebran ,

This method will not work for what you are trying to do.

I would suggest exploring the posts under this category:

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.32

 

Regardless, I would suggest you don't even need to do this using dialogs. Check out the FabricationConfuguration object. Not something I've had dealings with, but it may have what you need. https://www.revitapidocs.com/2020/119c73a2-a113-aa8c-e032-e80d22e31ac8.htm 

 

Regardless of your decided method, I suggest that any issues you come up against should be in their own forum post. That way you'll have multiple people looking at it.


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 12 of 13

TheRealChrisHildebran
Advocate
Advocate

Thanks for the feedback Matt! 

 

I definitely do look at Jeremy's gold mine and refer to the Revit API docs daily and incidentally. They are both tabs that open immediately upon opening my browser. 😁 In this case there is no event in the Revit API Class you linked to.

 

Normally i would have opened a new post but i think my question just extended the original post a bit keeping them connected.

 

Simply wanted to see if you had any experience with your solution to the OP working on non-Ribbon items.

0 Likes
Message 13 of 13

matthew_taylor
Advisor
Advisor
Ah, I have seen your other post which spells out your purpose. I'll reply there.

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?
0 Likes