Create New Ribbon with button

Create New Ribbon with button

Anonymous
Not applicable
1,564 Views
1 Reply
Message 1 of 2

Create New Ribbon with button

Anonymous
Not applicable

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);
        }
    }
}
0 Likes
1,565 Views
1 Reply
Reply (1)
Message 2 of 2

YuhanZhang
Autodesk
Autodesk

I don't look into your code much but there is a sample in our SDK to demonstrate how to create a custom environment in VB.Net that I think would help. You can find it in below folder after installing DeveloperTools.msi:

 

SDK\DeveloperTools\Samples\VB.NET\AddIns\CustomEnvironment\

 

Hope this helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes