This is what I did in C# to create a ribbon in the assembly environment. Hope it helps !
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Forms;
using Inventor;
using Microsoft.Win32;
using System.Linq;
namespace GenikAddin
{
/// <summary>
/// This is the primary AddIn Server class that implements the ApplicationAddInServer interface
/// that all Inventor AddIns are required to implement. The communication between Inventor and
/// the AddIn is via the methods on this interface.
/// </summary>
public class AddInParameters
{
//public static string addInCLSIDString;
}
[GuidAttribute("7AD36B50-4F53-4314-84E7-5F47BEF796C8")]
public class AddInServer : Inventor.ApplicationAddInServer
{
#region Data Members
//Inventor application object
private Inventor.Application m_inventorApplication;
//buttons
private DimGenButton m_DimGenButton;
private BomGeneratorButton m_BomGeneratorButton;
private DrawingToolsButton m_DrawingToolsButton;
private LoadProp.LoadPropButton m_LoadPropButton;
//user interface event
private UserInterfaceEvents m_userInterfaceEvents;
// ribbon panel
RibbonPanel m_drawingAnnotateDimGenRibbonPanel;
RibbonPanel m_AssemblyOrganikRibbonPanel;
//event handler delegates
private Inventor.UserInterfaceEventsSink_OnResetCommandBarsEventHandler UserInterfaceEventsSink_OnResetCommandBarsEventDelegate;
private Inventor.UserInterfaceEventsSink_OnResetEnvironmentsEventHandler UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate;
private Inventor.UserInterfaceEventsSink_OnResetRibbonInterfaceEventHandler UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate;
public static string addInCLSIDString;
#endregion
public AddInServer()
{
}
#region ApplicationAddInServer Members
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
{
try
{
//the Activate method is called by Inventor when it loads the addin
//the AddInSiteObject provides access to the Inventor Application object
//the FirstTime flag indicates if the addin is loaded for the first time
//initialize AddIn members
m_inventorApplication = addInSiteObject.Application;
Button.InventorApplication = m_inventorApplication;
//initialize event delegates
m_userInterfaceEvents = m_inventorApplication.UserInterfaceManager.UserInterfaceEvents;
UserInterfaceEventsSink_OnResetCommandBarsEventDelegate = new UserInterfaceEventsSink_OnResetCommandBarsEventHandler(UserInterfaceEvents_OnResetCommandBars);
m_userInterfaceEvents.OnResetCommandBars += UserInterfaceEventsSink_OnResetCommandBarsEventDelegate;
UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate = new UserInterfaceEventsSink_OnResetEnvironmentsEventHandler(UserInterfaceEvents_OnResetEnvironments);
m_userInterfaceEvents.OnResetEnvironments += UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate;
UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate = new UserInterfaceEventsSink_OnResetRibbonInterfaceEventHandler(UserInterfaceEvents_OnResetRibbonInterface);
m_userInterfaceEvents.OnResetRibbonInterface += UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate;
//load image icons for UI items
Icon BomGeneratorIcon = new Icon (new Icon(this.GetType(), "Organik.ico"), new Size(16,16));
Icon LoadPropIcon = new Icon(this.GetType(), "LoadProp1.ico");
//retrieve the GUID for this class
GuidAttribute addInCLSID;
addInCLSID = (GuidAttribute)GuidAttribute.GetCustomAttribute(typeof(AddInServer), typeof(GuidAttribute));
addInCLSIDString = "{" + addInCLSID.Value + "}";
m_BomGeneratorButton = new BomGeneratorButton("Bom Generator", "Autodesk:Organik:BomGenCmdBtn", CommandTypesEnum.kShapeEditCmdType, addInCLSIDString, "BomQuery", "Bom Generator", BomGeneratorIcon, BomGeneratorIcon, ButtonDisplayEnum.kDisplayTextInLearningMode);
m_LoadPropButton = new LoadProp.LoadPropButton("LoadProp", "Autodesk:Organik:LoadPropBtn", CommandTypesEnum.kShapeEditCmdType, addInCLSIDString, "LoadProp", "LoadProp Form", LoadPropIcon, LoadPropIcon, ButtonDisplayEnum.kDisplayTextInLearningMode);
//create the command category
CommandCategory bomCategory = m_inventorApplication.CommandManager.CommandCategories.Add("Bom", "Autodesk:Organik:Bom", addInCLSIDString);
bomCategory.Add(m_BomGeneratorButton.ButtonDefinition);
bomCategory.Add(m_LoadPropButton.ButtonDefinition);
if (firstTime == true)
{
//access user interface manager
UserInterfaceManager userInterfaceManager;
userInterfaceManager = m_inventorApplication.UserInterfaceManager;
InterfaceStyleEnum interfaceStyle;
interfaceStyle = userInterfaceManager.InterfaceStyle;
//create the UI for classic interface
if (interfaceStyle == InterfaceStyleEnum.kClassicInterface)
{
CommandBar bomCommandBar;
bomCommandBar = userInterfaceManager.CommandBars.Add("BOM", "Autodesk:Organik:BomGenToolBar", CommandBarTypeEnum.kRegularCommandBar, addInCLSIDString);
bomCommandBar.Controls.AddButton(m_BomGeneratorButton.ButtonDefinition, 0);
bomCommandBar.Controls.AddButton(m_LoadPropButton.ButtonDefinition, 0);
//Get the drawing environment base object
Inventor.Environment drawingEnvironment;
drawingEnvironment = userInterfaceManager.Environments["DLxDrawingEnvironment"];
//make this command bar accessible in the panel menu for the drawing environment.
drawingEnvironment.PanelBar.CommandBarList.Add(dimGenCommandBar);
//Get Assembly environment base object
Inventor.Environment assemblyEnvironment;
assemblyEnvironment = userInterfaceManager.Environments["AMxAssemblyEnvironment"];
//make this command bar accessible in the panel menu for the drawing environment.
assemblyEnvironment.PanelBar.CommandBarList.Add(bomCommandBar);
}
//create the UI for ribbon interface
else
{
//get the ribbon associated with Drawing document
Inventor.Ribbons ribbons;
ribbons = userInterfaceManager.Ribbons;
//get the ribbon Associated with Assembly document
Inventor.Ribbon assemblyRibbon;
assemblyRibbon = ribbons["Assembly"];
//get tabs associated with assembly ribbon
RibbonTabs assemblyRibbonTabs;
assemblyRibbonTabs = assemblyRibbon.RibbonTabs;
RibbonTab assemblyRibbonTab;
assemblyRibbonTab = assemblyRibbonTabs.Add("Organik", "Autodesk:Organik:Bom", addInCLSIDString);
//Create new panel with the tab
RibbonPanels assemblyRibbonPannels;
assemblyRibbonPannels = assemblyRibbonTab.RibbonPanels;
m_AssemblyOrganikRibbonPanel = assemblyRibbonPannels.Add("Organik", "Autodesk:Organik:AssemblyRibbonPanel", Guid.NewGuid().ToString());
//add controls to the Organik Assembly Pannel
CommandControls organikAssemblyRibbonPanelCtrls;
organikAssemblyRibbonPanelCtrls = m_AssemblyOrganikRibbonPanel.CommandControls;
CommandControl bomGeneratorButtonControl;
bomGeneratorButtonControl = organikAssemblyRibbonPanelCtrls.AddButton(m_BomGeneratorButton.ButtonDefinition);
CommandControl WPFFormButtonControl;
WPFFormButtonControl = organikAssemblyRibbonPanelCtrls.AddButton(m_LoadPropButton.ButtonDefinition);
}
}
//Dummy connection to server to prevent first load delay when running
string dummy;
using (var context = new OrganikDB.OrganikSQL(@"Data Source = M005\GENIKERP; Initial Catalog = OrganikSQL; Persist Security Info = True; User ID = SecuriteOrganik; Password = genik123"))
{
dummy = context.tabTmtGrp.Select(x => x.Materiel).FirstOrDefault();
}
//MessageBox.Show ("To access the commands of the sample addin, activate a 2d sketch of a part \n document and select the \"AddInSlot\" toolbar within the panel menu");
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
}
public void Deactivate()
{
//the Deactivate method is called by Inventor when the AddIn is unloaded
//the AddIn will be unloaded either manually by the user or
//when the Inventor session is terminated
try
{
m_userInterfaceEvents.OnResetCommandBars -= UserInterfaceEventsSink_OnResetCommandBarsEventDelegate;
m_userInterfaceEvents.OnResetEnvironments -= UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate;
UserInterfaceEventsSink_OnResetCommandBarsEventDelegate = null;
UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate = null;
m_userInterfaceEvents = null;
if (m_AssemblyOrganikRibbonPanel != null)
{
m_AssemblyOrganikRibbonPanel.Delete();
}
//release inventor Application object
Marshal.ReleaseComObject(m_inventorApplication);
m_inventorApplication = null;
GC.WaitForPendingFinalizers();
GC.Collect();
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
}
public void ExecuteCommand(int CommandID)
{
//this method was used to notify when an AddIn command was executed
//the CommandID parameter identifies the command that was executed
//Note:this method is now obsolete, you should use the new
//ControlDefinition objects to implement commands, they have
//their own event sinks to notify when the command is executed
}
public object Automation
{
//if you want to return an interface to another client of this addin,
//implement that interface in a class and return that class object
//through this property
get
{
return null;
}
}
private void UserInterfaceEvents_OnResetCommandBars(ObjectsEnumerator commandBars, NameValueMap context)
{
try
{
CommandBar commandBar;
for (int commandBarCt = 1; commandBarCt <= commandBars.Count; commandBarCt++)
{
commandBar = (Inventor.CommandBar)commandBars[commandBarCt];
if (commandBar.InternalName == "Autodesk:Organik:BomGenToolBar")
{
//add buttons to toolbar
commandBar.Controls.AddButton(m_BomGeneratorButton.ButtonDefinition, 0);
commandBar.Controls.AddButton(m_LoadPropButton.ButtonDefinition, 0);
return;
}
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
private void UserInterfaceEvents_OnResetEnvironments(ObjectsEnumerator environments, NameValueMap context)
{
try
{
Inventor.Environment environment;
for (int environmentCt = 1; environmentCt <= environments.Count; environmentCt++)
{
if (environment.InternalName == "AMxAssemblyEnvironment")
{
//make this command bar accessible in the panel menu for the 3d Assembly environment.
environment.PanelBar.CommandBarList.Add(m_inventorApplication.UserInterfaceManager.CommandBars["Autodesk:Organik:BomGenToolBar"]);
return;
}
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
private void UserInterfaceEvents_OnResetRibbonInterface(NameValueMap context)
{
try
{
UserInterfaceManager userInterfaceManager;
userInterfaceManager = m_inventorApplication.UserInterfaceManager;
//get the ribbon associated with Drawing document
Inventor.Ribbons ribbons;
ribbons = userInterfaceManager.Ribbons;
//get the ribbon Associated with Assembly document
Inventor.Ribbon assemblyRibbon;
assemblyRibbon = ribbons["Assembly"];
//get tabs associated with assembly ribbon
RibbonTabs assemblyRibbonTabs;
assemblyRibbonTabs = assemblyRibbon.RibbonTabs;
RibbonTab assemblyRibbonTab;
assemblyRibbonTab = assemblyRibbonTabs.Add("Organik", "Autodesk:Organik:Bom", Guid.NewGuid().ToString());
//Create new panel with the tab
RibbonPanels assemblyRibbonPannels;
assemblyRibbonPannels = assemblyRibbonTab.RibbonPanels;
m_AssemblyOrganikRibbonPanel = assemblyRibbonPannels.Add("Organik", "Autodesk:Organik:AssemblyRibbonPanel", Guid.NewGuid().ToString());
//add controls to the Organik Assembly Pannel
CommandControls organikAssemblyRibbonPanelCtrls;
organikAssemblyRibbonPanelCtrls = m_AssemblyOrganikRibbonPanel.CommandControls;
CommandControl bomGeneratorButtonControl;
bomGeneratorButtonControl = organikAssemblyRibbonPanelCtrls.AddButton(m_BomGeneratorButton.ButtonDefinition);
CommandControl WPFFormButtonControl;
WPFFormButtonControl = organikAssemblyRibbonPanelCtrls.AddButton(m_LoadPropButton.ButtonDefinition);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
#endregion
}
}