How can I remove an event after updating the items of RibbonSplitButton ( remove childs and add new childs )

How can I remove an event after updating the items of RibbonSplitButton ( remove childs and add new childs )

abdechafi.neji
Contributor Contributor
379 Views
2 Replies
Message 1 of 3

How can I remove an event after updating the items of RibbonSplitButton ( remove childs and add new childs )

abdechafi.neji
Contributor
Contributor

Hello , I'm trying to remove the event listeners of Childs of RibbonSplitButton , the update works good but I need to remove the event listener . 

 

I've tried this code , but it doesn't work.  However, when I'm try clicking on any of button , it will execute multiple times ( multiple calling of the execute event ) .

 

 

public void RemoveEvent(int btn_ID)
  {
    BtnID = btnID;
    BtnDef.OnExecute -= BtnDef_OnExecute;
  }

// Calling removeEvent 
// SplitBtn is my RibbonSplitButton

 foreach (CommandControl child in SplitBtn.ChildControls)
                    {
                        child.Delete();
                        if (Btns_indexCopy.Count() > 0)
                       {
                          _BtnDefEvents.RemoveEvent(Btns_indexCopy[counter]);
                       }
                    }

 

0 Likes
380 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

It might depend on how the code behind the buttons was done.  When a simple event handler is created by an iLogic rule, that same rule must have also included a way to remove that event handler, and then when the specified condition(s) are met, that code will remove the handler on its own.  If no code for removing the event handler was included, then the only way to get rid of the event handler is to restart Inventor, because the event handler is being held in Inventor's session memory.  But iLogic rules and command buttons can operate differently.  What you described sounds to me like the iLogic rule scenario, where if you ran the rule multiple times, there will be multiple event handlers held in Inventor's session memory, because there is no way to remove it remotely from another code (at least not that I have ever heard of).  I would assume that removing the button from the user interface would remove the event handler, but I haven't done a ton of buttons for custom, non-macro, non-built-in type commands yet.  I have dabbled with creating buttons to run external iLogic rules prior to the 2023-24 releases of Inventor, but those simply run an iLogic rule once, and do not repeat themselves that I have noticed yet.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

abdechafi.neji
Contributor
Contributor

My code involves adding button definitions, either a single button definition or multiple button definitions, every time the collection changes. I have a collection bound to the items of a RibbonSplitButton.

 

To be more specific, I use the AddButtonDefinition method to add an item to the existing SplitButton control each time. I have two SplitButtons, and I need to change their collections dynamically. The items in RibbonSplitButton1 are different from those in RibbonSplitButton2. Therefore, I need to update the collections for both SplitButtons. However, I'm encountering two problems. Firstly, the event is being called multiple times after updating the RibbonSplitButton collection. Secondly, some items are not executing properly.

 

I'm wondering if there is a way to modify the RibbonSplitButton to function like a combobox, where the collection acts as a list of items. This way, I can treat it as an item rather than a button with a click event.

0 Likes