Hi there,
Hope this will get you going:
using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Windows;
using AutoCAD = Autodesk.AutoCAD.ApplicationServices.Application;
using Ribbon = Autodesk.AutoCAD.Ribbon.RibbonServices;
using Kraan.Btm.Forms;
[assembly: ExtensionApplication(typeof(Kraan.Btm.Application))]
namespace Kraan.Btm
{
public class RibbonComboSample : IExtensionApplication
{
private RibbonCombo _ribCom = new RibbonCombo();
void IExtensionApplication.Initialize()
{
AutoCAD.SystemVariableChanged +=
new SystemVariableChangedEventHandler(Application_SystemVariableChanged);
//Check if Netloaded or loaded on startup
//If dll is load on autocad startup Ribbon is not created yet. Setup event to watch if ribbon is created.
if (Autodesk.Windows.ComponentManager.Ribbon == null)
{
Autodesk.Windows.ComponentManager.ItemInitialized +=
new EventHandler<RibbonItemEventArgs>(ComponentManager_ItemInitialized);
}
else
{
//dll is netloaded is avalible create the ribbon.
CreateRibbon();
}
}
void IExtensionApplication.Terminate()
{
AutoCAD.SystemVariableChanged -= new Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(Application_SystemVariableChanged);
}
private void Application_SystemVariableChanged(object sender, SystemVariableChangedEventArgs e)
{
if (e.Name == "WSCURRENT")
{
CreateRibbon();
}
}
private void CreateRibbon()
{
try
{
RibbonControl ribCntrl = Ribbon.RibbonPaletteSet.RibbonControl;
if (ComponentManager.Ribbon == null) return;
for (int i = 0; i < ribCntrl.Tabs.Count; i++)
{
if (ribCntrl.Tabs[i].Id.Equals("MyID")) return;
}
//add the tab
RibbonTab ribTab = new RibbonTab();
ribTab.Title = "My New RibbonTab";
ribTab.Id = "MyID";
ribCntrl.Tabs.Add(ribTab);
//create and add the panel
CreateRibbonPanel(ribTab);
}
catch(SystemException ex)
{
}
}
public void CreateRibbonPanel(RibbonTab ribTab)
{
//create the panel source
RibbonPanelSource _ribSourcePanel = new RibbonPanelSource();
_ribSourcePanel.Title = "New Ribbon Panel";
//now the panel
RibbonPanel ribPanel = new RibbonPanel();
ribPanel.Source = _ribSourcePanel;
ribTab.Panels.Add(ribPanel);
#region RibbonButtons
RibbonButton ribBut01 = new RibbonButton();
ribBut01.Text = "Combo Item 01";
ribBut01.Id = "Item01";
ribBut01.ShowText = true;
//ribBut01.ShowImage = true;
//_rbNewSymbol.LargeImage = Img.getBitmap(Properties.Resources.New_Symbol_32);
//_rbNewSymbol.Orientation = System.Windows.Controls.Orientation.Vertical;
RibbonButton ribBut02 = new RibbonButton();
ribBut02.Text = "Combo Item 02";
ribBut02.Id = "Item02";
ribBut02.ShowText = true;
//ribBut01.ShowImage = true;
//_rbNewSymbol.LargeImage = Img.getBitmap(Properties.Resources.New_Symbol_32);
//_rbNewSymbol.Orientation = System.Windows.Controls.Orientation.Vertical;
# endregion
//Set RibbonCombo Properties
_ribCom.Text = "";
_ribCom.ShowText = false;
_ribCom.Width = 200;
//Populate the RibbonCombo
_ribCom.Items.Add(ribBut01);
_ribCom.Items.Add(ribBut02);
RibbonRowPanel RowPanel = new RibbonRowPanel();
RowPanel.Items.Add(_ribCom);
}
[CommandMethod("GetCurrentRibbonComboItem")]
public void GetCurrentRibbonComboItem()
{
if (_ribCom.Items.Count != 0)
{
RibbonButton but = (RibbonButton)_ribCom.Current;
switch (but.Id)
{
case "Item01":
AutoCAD.ShowAlertDialog("Ribbon Item 01 is selected");
break;
case "Item02":
AutoCAD.ShowAlertDialog("Ribbon Item 01 is selected");
break;
default:
AutoCAD.ShowAlertDialog("Error Getting Current RibbonCombo Item");
break;
}
}
}
void ComponentManager_ItemInitialized(object sender, RibbonItemEventArgs e)
{
if (Autodesk.Windows.ComponentManager.Ribbon != null)
{
//ok, create Ribbon
CreateRibbon();
//and remove the event handler
Autodesk.Windows.ComponentManager.ItemInitialized -= new EventHandler<RibbonItemEventArgs>(ComponentManager_ItemInitialized);
}
}
}
}
It's a shame when a button is added to a combobox it can't use the commandhandler of the button. It's has some events when. CurrentItemChanged. This way you can set variables in your application.
Again hope it helps. Code is not tested it's copy pasted from my application.
Kind regards,
Irvin