Buttons and Button Definitions

Top  Previous  Next

See this page also, it has a full implementation.

 

A button definition has two functions:

 

1.It is a definition of the aspect, look of the button
2.It has an OnExecute member which lets you react to a user clicking on the button

 

Note that a button definition is not a button, that will be explained later.

 

Icons of a button are optional, and can be of two sizes Normal size icons are 16 pixels wide by 16 pixels high. Large icons are 32 pixels wide by 32 pixels high. If an icon of a different size is provided, Inventor will scale it to fit.
 

A good place to actually add an instance of a button is in the Activate member of your addin. Read and understand the comments here:

 

 

       public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)

       {

           // This 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;

 

           // Control definitions are definitons of things like buttons and menus...

           ControlDefinitions controlDefs = m_inventorApplication.CommandManager.ControlDefinitions;

 

           // Create a *definition* of a button, what it looks like mainly...

           m_buttonDefinition = controlDefs.AddButtonDefinition("Owen's Button",

                                                                "invrSampleCommand",

                                                                Inventor.CommandTypesEnum.kShapeEditCmdType,

                                                                "{786675cb-d781-4f02-bfaa-02c4fda0ba61}",

                                                                "Owens Desc", "Owens Tooltip") ;

           m_buttonDefinition.Enabled = true;

 

           // Now we have to *place* the button somewhere.

           // This is a lot of drilling down...

 

           // Get the object which handles the user interface...

           UserInterfaceManager userInterfaceManager;

           userInterfaceManager = m_inventorApplication.UserInterfaceManager;       

 

           // Get the list of ribbons...

           Inventor.Ribbons ribbons;

           ribbons = userInterfaceManager.Ribbons;

 

           // Get the "Part" ribbon, a list of tabs active when editing a part...

           Inventor.Ribbon partRibbon;

           partRibbon = ribbons["Part"];

 

           // Get the tabs associated with part ribbon

           RibbonTabs ribbonTabs;

           ribbonTabs = partRibbon.RibbonTabs;

 

           // In particular get the "tools" tab...

           RibbonTab partSketchRibbonTab;

           partSketchRibbonTab = ribbonTabs["id_TabTools"];

 

           // Inside the "Tools" tab there are many panels...

           RibbonPanels ribbonPanels;

           ribbonPanels = partSketchRibbonTab.RibbonPanels;

 

           // Get the measurepent panel...

           RibbonPanel ribbonPanel;

           ribbonPanel = ribbonPanels["id_PanelP_ToolsMeasure"] ;

 

           // Finally we can add the button...

           ribbonPanel.CommandControls.AddButton(m_buttonDefinition);

       }

 

The Gui heirachy is illustrated here:

 

Gui-Levels

 

 

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)