Change button order on ribbon from addin C#

Change button order on ribbon from addin C#

gert-leonvanlier
Collaborator Collaborator
388 Views
2 Replies
Message 1 of 3

Change button order on ribbon from addin C#

gert-leonvanlier
Collaborator
Collaborator

I have read several forum post on this and other forums and websites, however it is still not clear to me: how can you change the button order/the place a button is placed using the API?

I know it has to do with InsertBeforeTargetControl in the AddButton method from the API, but how is that working? I assume a button has an internal name (TargetControlInternalName). Or is that the name of the button it should replace when you set InsertBeforeTargetControl to true or false?

Currently I have this code for my butons, showing up on our company tab (and two buttons on a drawing tab):

if (!(PropertyEditorButton == null))
{
	Panel_Properties_prt.CommandControls.AddButton(PropertyEditorButton, true, true, "PropertyEditorButtonPanelPropertiesPrt");
	Panel_Properties_asm.CommandControls.AddButton(PropertyEditorButton, true, true, "PropertyEditorButtonPanelPropertiesAsm");
	Panel_Properties_dwg.CommandControls.AddButton(PropertyEditorButton, true, true, "PropertyEditorButtonPanelPropertiesDwg");
	//Panel_Properties_prn.CommandControls.AddButton(PropertyEditorButton, true, true, "PropertyEditorButtonPanelPropertiesprn");
}

if (!(ContentListButton == null))
{
	Panel_Layouting_Asm.CommandControls.AddButton(ContentListButton, true, true, "ContentListButtonPanelLayoutingAsm");
}

if (!(SystemLayoutChecklistButton == null)) { Panel_Layouting_Asm.CommandControls.AddButton(SystemLayoutChecklistButton, true, true, "LayoutCheckListButtonPanelLayoutingAsm"); }

if (!(SheetSizeDownButton == null))
{
	Panel_Drawing_Dwg.CommandControls.AddButton(SheetSizeDownButton, true, true, "SheetSizeDownButtonPanelDrawingDwg");
	dwgRibbon.RibbonTabs["id_TabPlaceViews"].RibbonPanels["id_PanelD_PlaceViewsSheets"].CommandControls.AddButton(SheetSizeDownButton, true, true, "SheetSizeDownButtonPanelPlaceViewSheets");
}

if (!(SheetSizeUpButton == null))
{
	Panel_Drawing_Dwg.CommandControls.AddButton(SheetSizeUpButton, true, true, "SheetSizeUpButtonPanelDrawingDwg);
	dwgRibbon.RibbonTabs["id_TabPlaceViews"].RibbonPanels["id_PanelD_PlaceViewsSheets"].CommandControls.AddButton(SheetSizeUpButton, true, true, "SheetSizeUpButtonPanelPlaceViewSheets");
}

Panel_Drawing_Dwg.CommandControls.AddSeparator();

if (!(DrawingUpdateButton == null)) { Panel_Drawing_Dwg.CommandControls.AddButton(DrawingUpdateButton, true, true, "DrawingUpdateButtonPanelDrawingDwg"); }

if (!(SettingsButton == null))
{
	Panel_Settings_Zero.CommandControls.AddButton(SettingsButton, true, true, "SettingsButtonPanelSettingsZero");
	Panel_Settings_Prt.CommandControls.AddButton(SettingsButton, true, true, "SettingsButtonPanelSettingsPrt");
	Panel_Settings_Asm.CommandControls.AddButton(SettingsButton, true, true, "SettingsButtonPanelSettingsAsm");
	Panel_Settings_Dwg.CommandControls.AddButton(SettingsButton, true, true, "SettingsButtonPanelSettingsDwg");
	Panel_Settings_Prn.CommandControls.AddButton(SettingsButton, true, true, "SettingsButtonPanelSettingsPrn");
}

 

I want the SettingsButton to be placed at the end of all other buttons. How should I do this?

 

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

Michael.Navara
Advisor
Advisor

Usually I create my own panels for addin and then the controls order depends on call order of AddButton methods.

 

To your question. 

TargetControlInternalName is internal name of control you wat to place your control next to. 

InsertBeforeTargetControl defines if you want to place your control left/right for large buttons, above/below for small buttons.

Message 3 of 3

gert-leonvanlier
Collaborator
Collaborator

I also create my own tab and panels.

 

I think I understand the use of TargetControlInterName and InsertBeforeTargetControl. However, it is not working for some reason.

 

For example: I have a button with Internal Name "Property_Editor_button".

Then there is a settings button. I want the settings button to be placed before "Property_Editor_button". So I would assume the code for creating the settings button on the panel should be

 

Panel_Settings_dwg.CommandControls.AddButton(SettingsButton, true, true, "Property_Editor_button", true);

 

 

However, when starting Inventor I get this message and the addin is not loaded.

yfWyJaUwwT.png

 

When I change the code to the following, the addin loads without a problem.

 

Panel_Settings_dwg.CommandControls.AddButton(SettingsButton, true);

 

 

So something is not working right. Any ideas?

0 Likes