Message 1 of 2
Create New Ribbon with button
Not applicable
05-23-2012
01:50 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Can anyone help with on how to create a ribbon with a button. I am creating an add-in for Inventor. I am trying to put this code in the Activate Sub but it's not adding the ribbon once I open a drawing. Just trying to use this example to get me started.
Thanks,
Ted
public void AddParallelEnvironment()
{
Application oApp = ThisApplication;
// Get the Environments collection
Environments oEnvironments = oApp.UserInterfaceManager.Environments;
// Create a new environment
Inventor.Environment oNewEnv = oEnvironments.Add("Some Analysis", "SomeAnalysis", null, null, null);
// Get the ribbon associated with the assembly environment
Ribbon oAssemblyRibbon = oApp.UserInterfaceManager.Ribbons["Assembly"];
// Create contextual tabs and panels within them
RibbonTab oContextualTabOne = oAssemblyRibbon.RibbonTabs.Add("Some Analysis", "SomeAnalysis", "ClientId123","" ,false , true);
RibbonPanel oPanelOne = oContextualTabOne.RibbonPanels.Add("Panel One", "PanelOne", "ClientId123","", false);
ButtonDefinition oDef1 = (ButtonDefinition)oApp.CommandManager.ControlDefinitions["PartExtrudeCmd"];
oPanelOne.CommandControls.AddButton(oDef1, true, true, "", false);
RibbonPanel oPanelTwo = oContextualTabOne.RibbonPanels.Add("Panel Two", "PanelTwo", "ClientId123", "", false);
ButtonDefinition oDef2 = (ButtonDefinition)oApp.CommandManager.ControlDefinitions["AssemblyPlaceComponentCmd"];
oPanelTwo.CommandControls.AddButton(oDef2, true, true, "", false);
RibbonTab oContextualTabTwo = oAssemblyRibbon.RibbonTabs.Add("Some Analysis Extras", "SomeAnalysisExtras", "ClientId123","" ,false , true);
RibbonPanel oPanelThree = oContextualTabTwo.RibbonPanels.Add("Panel Three", "PanelThree", "ClientId123", "", false);
oPanelThree.CommandControls.AddButton(oDef1, true, true, "", false);
// Associate the contextual tabs with the newly created environment
// The contextual tabs will only be displayed when this environment is active
String[] strTabs = new String[2];
strTabs[0] = "SomeAnalysis";
strTabs[1] = "SomeAnalysisExtras";
oNewEnv.AdditionalVisibleRibbonTabs = strTabs;
// Make the "SomeAnalysis" tab default for the environment
oNewEnv.DefaultRibbonTab = "SomeAnalysis";
// Get the collection of parallel environments and add the new environment
EnvironmentList oParEnvs = oApp.UserInterfaceManager.ParallelEnvironments;
oParEnvs.Add(oNewEnv);
// Make the new parallel environment available only within the assembly environment
// A ControlDefinition is automatically created when an environment is added to the
// parallel environments list. The internal name of the definition is the same as
// the internal name of the environment.
ControlDefinition oParallelEnvButton = oApp.CommandManager.ControlDefinitions["SomeAnalysis"];
int iEnvCount = oEnvironments.Count;
Inventor.Environment oEnv;
int i;
for (i = 1; i <= iEnvCount; i++)
{
oEnv = oEnvironments[i];
if (oEnv.InternalName != "AMxAssemblyEnvironment")
{
oEnv.DisabledCommandList.Add(oParallelEnvButton);
}
}
}
