Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Custom menu

8 REPLIES 8
Reply
Message 1 of 9
GeorgK
630 Views, 8 Replies

Custom menu

Hello together,

 

I have an add-in. How could I add a entry to the menu? Is there a sample for it?

 

Thank you very much

 

Georg

 

 

8 REPLIES 8
Message 2 of 9
GeorgK
in reply to: GeorgK

Message 3 of 9
noontz
in reply to: GeorgK

You will need a few undocumented features, as far as I can see 

 

The CommandManager.UserInputEvents has an event OnContextMenu.

 

The handler has this signature :

 

(SelectionDeviceEnum SelectionDevice, NameValueMap AdditionalInfo, CommandBar CommandBar) : void

 

You can add your own ButtonDefinition to the commandbar : CommandBar.Controls.AddButton(myBut, 2)

 

There´s seems to be a lot of undocumented CommandBar stuff under the hood, and you will need to filter your handler or save the ID of the specific CommandBar.

 

Hope this will get you started!

 

 

Message 4 of 9
GeorgK
in reply to: noontz

Thank you very much.

 

@Autodesk: Please could you provide some samples?

Message 5 of 9
GeorgK
in reply to: GeorgK

Do you have an example for it? Thank you.

Message 6 of 9
Boorda
in reply to: GeorgK

Oops, after posting I noticed you were asking specifically about menus and not the ribbon. I will leave this for now tho in case someone else might find it useful, or a moderator could possibly move it to a more directly related thread.  Sorry about that!

 

Not sure if this helps, but this is the manual way that I go about adding my addins to the ribbons....

 

In the StandardAddinServer.vb after....

 

Namespace YourAddinAssemblyName

    <ProgIdAttribute("YourAddinAssemblyName.StandardAddInServer"), _

  GuidAttribute("Your Addin's GUID here"), ComVisible(True)> PublicClassStandardAddInServer  

  ImplementsInventor.ApplicationAddInServer

       

   ' Inventor application object.

       Private_AppAsInventor.Application

 

Add...

 

       Privatem_ClientID As String = "Your Addin's GUID here"  

 

Replacing the"Your Addin's GUID here" with your addin's GUID, do not include the brackets.

 

Then in your..

 

  Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, _

                      ByVal firstTime As Boolean) _

                      Implements Inventor.ApplicationAddInServer.Activate

 

                   ' Initialize AddIn members.             

                   _App = addInSiteObject.Application

 

 

Define you button images. Since I use the vb.net 4.5 framework I use the AxHostConverter method.

I can provide you with that code if you need it.

 

                ' Define Button Images

                ' Using the AxHostConverter method to convert button images for addins using above .net4.

                

                ' Standard (Small) Icon Def.
                Dim ReattachSICO = AxHostConverter.ImageToPictureDisp(YOURSMALLICON

               ' Large Icon def.

                Dim ReattachLICO = AxHostConverter.ImageToPictureDisp(YOURLARGEICON)  

 

Now you need to create the command button definition.

Change the values to fit your addin parameters.

 

                ' Create the button definitions.
                ' Attach Button.
                
Attach_ButtonDef = controlDefs.AddButtonDefinition(DisplayName, InternalName, _
                                                                    CommandTypesEnum.kQueryOnlyCmdType, _
                                                                    m_ClientID, _
                                                                    Description, _    
                                                                    ToolTipText, _
          
                                                          ReattachSICO, ReattachLICO)

 

                           ' Only runs the first time you addin is activated by Inventor.

                            If firstTime Then        

                                     ' Get the ribbon for Inventor Enviroment you need to add your button to.        

                                     ' Part Ribbon         

                                      Dim PRT_RIB As Ribbon = _App.UserInterfaceManager.Ribbons.Item("Part")

 

                                     ' Define the tab you want your button to populate in.                     

                                      Dim rTab As RibbonTab = PRT_RIB.RibbonTabs.Add(DisplayName, InternalName, _

                                                                                                                      m_cliantID, "id_TabTools")

 

                                     ' Define a panel insode of the tab you just created.                      

                                     Dim rPanl As RibbonPanel = rTab.RibbonPanels.Add(DisplayName, InternalName, m_cliantID

 

                                    ' Add you command definition to the panel you just created/referemced.                       

                                    rPanl.CommandControls.AddButton(Attach_ButtonDef)

                             end if

 

 

Make sure that when you create new Ribbon Tabs, Panels & Buttons that you always use a different InternalName for each.

I usually name them by AssemblyName_ItemDisplayName_ObjectTyp

 

For example the InternalName for one of my Panels is AFR_Attach_PNL

 

 

Anyway hope that helps and doesn't confuse you!


Automation is key!
Message 7 of 9
noontz
in reply to: GeorgK

Here´s the answer from before implementet in a testclass ( C# ). Take it from there, and please mark as solution if this is what you are looking for 😉

public class ContextMenuTestClass
{
readonly Application _myInventor;
readonly ButtonDefinition _myBut;
public ContextMenuTestClass(Application myInventor)
{
if(myInventor == null) return; _myInventor = myInventor; try { _myBut = _myInventor.CommandManager.ControlDefinitions.AddButtonDefinition("noontz", "id_noontz", CommandTypesEnum .kQueryOnlyCmdType, null, null, null, null, null, ButtonDisplayEnum .kNoTextWithIcon); } catch { _myBut = (ButtonDefinition) _myInventor.CommandManager.ControlDefinitions["id_noontz"]; } _myBut.OnExecute += myBut_OnExecute; _myInventor.CommandManager.UserInputEvents.OnContextMenu += userInputs_OnContextMenu; } void myBut_OnExecute(NameValueMap context) { MessageBox.Show("Noontz is in the house"); } void userInputs_OnContextMenu(SelectionDeviceEnum selectionDevice, NameValueMap additionalInfo, CommandBar commandBar) { commandBar.Controls.AddButton(_myBut, 1); } }
Message 8 of 9
philippe.leefsma
in reply to: noontz

Customizing the context menu isn't an undocumented feature, it depends which version of Inventor you are talking about, some of the APIs have been deprecated and replaced by newer ones.

 

If you are using 2012 or later release, you shouldn't use OnContextMenu as pointed out earlier in that thread. Here is a post that describes how to customize the context menu using the supported and documented APIs:

 

http://adndevblog.typepad.com/manufacturing/2012/05/customizing-radialmarkingmenu-and-linearmarkingm...

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 9 of 9
noontz
in reply to: philippe.leefsma

Hi Philippe

 

Thanks for straightening things up!!

 

& lucky me I put the "as far as I can see"  in the first post Smiley Wink


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report