Adding Menu Item

Adding Menu Item

Anonymous
Not applicable
318 Views
4 Replies
Message 1 of 5

Adding Menu Item

Anonymous
Not applicable
Can anyone give me some straightforward code (for R9) for adding a menu item to the "Tools" (or any for that matter) menu? I have code for pre-R8 but I'd like to use the new supported code. The help files don't quite get me there. Maybe I'm just being dense today. TIA -- Sean Dotson, PE www.sdotson.com Autodesk Inventor Certified Expert Sidel, Engineering & Manufacturing Manager
0 Likes
319 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
This code works in IV8 and IV9 addin..Add this code to a class module. I hope this helps. Option Explicit 'Form should be loaded in modality mode. Public Enum frmModality frmModal = vbModal frmModeless = vbModeless End Enum 'Implements for ApplicationAddInServer Implements ApplicationAddInServer 'Public AddInSite As ApplicationAddInSite Public AddInSite As ApplicationAddInSite 'Public InventorApp As InventorFramework.Application Public InventorApp As Inventor.Application 'Define command. Private Command1 As Command Public Sub ApplicationAddInServer_Activate(ByVal AddInSiteObject As Inventor.ApplicationAddInSite, ByVal FirstTime As Boolean) 'Inside Activate 'Save the Add-In site object in a global variable. Set AddInSite = AddInSiteObject 'Save the Invertor Application object. Set InventorApp = AddInSite.Application 'Create the first command. Set Command1 = AddInSite.CreateCommand("Property Management", 1, True) 'Set command to enabled to use command properties. Command1.Enabled = True Set AddInSite = Nothing Set InventorApp = Nothing Set Command1 = Nothing End Sub 'These subs must be here even there is not any code otherwise compiler deletes these subs and 'program dosn't work. 'Public Property Get ApplicationAddInServer_Automation() As Inventor.AddInAutomation Public Property Get ApplicationAddInServer_Automation() As Object 'Inside Automation End Property Public Sub ApplicationAddInServer_Deactivate() 'Inside Deactivate End Sub Public Sub ApplicationAddInServer_ExecuteCommand(ByVal CommandID As Long) 'If program is executed by clicking it from Tools bar then we will call it's form. Select Case CommandID Case 1 Call ShowPropertiesForm End Select End Sub Public Sub ShowForm(Optional Modality As _ frmModality = frmModal) 'Call frm Form as Modality mode. frm.Show Modality End Sub Public Sub ShowPropertiesForm(Optional Modality As _ frmModality = frmModal) 'Call frmProperties form as Modality mode. frmProperties.Show Modality End Sub Public Sub ShowDrawingSettingsForm(Optional Modality As frmModality = frmModal) frmDrawingSettings.Show Modality End Sub
0 Likes
Message 3 of 5

Anonymous
Not applicable
While this will work I do believe this is the old method. It works in R9 but will not be supported so may break in future versions. If I'm wrong please let me know. -- Sean Dotson, PE www.sdotson.com Autodesk Inventor Certified Expert Sidel, Engineering & Manufacturing Manager "Mika Aaltonen" wrote in message news:41c186a0_3@newsprd01... > This code works in IV8 and IV9 addin..Add this code to a class module. I > hope this helps. > > Option Explicit > > 'Form should be loaded in modality mode. > Public Enum frmModality > frmModal = vbModal > frmModeless = vbModeless > End Enum > > 'Implements for ApplicationAddInServer > Implements ApplicationAddInServer > > 'Public AddInSite As ApplicationAddInSite > Public AddInSite As ApplicationAddInSite > 'Public InventorApp As InventorFramework.Application > Public InventorApp As Inventor.Application > > 'Define command. > Private Command1 As Command > > Public Sub ApplicationAddInServer_Activate(ByVal AddInSiteObject As > Inventor.ApplicationAddInSite, ByVal FirstTime As Boolean) > 'Inside Activate > > 'Save the Add-In site object in a global variable. > Set AddInSite = AddInSiteObject > > 'Save the Invertor Application object. > Set InventorApp = AddInSite.Application > > 'Create the first command. > Set Command1 = AddInSite.CreateCommand("Property Management", 1, True) > > 'Set command to enabled to use command properties. > Command1.Enabled = True > > Set AddInSite = Nothing > Set InventorApp = Nothing > Set Command1 = Nothing > End Sub > > 'These subs must be here even there is not any code otherwise compiler > deletes these subs and > 'program dosn't work. > > 'Public Property Get ApplicationAddInServer_Automation() As > Inventor.AddInAutomation > Public Property Get ApplicationAddInServer_Automation() As Object > 'Inside Automation > End Property > > Public Sub ApplicationAddInServer_Deactivate() > 'Inside Deactivate > End Sub > > Public Sub ApplicationAddInServer_ExecuteCommand(ByVal CommandID As Long) > 'If program is executed by clicking it from Tools bar then we will call it's > form. > Select Case CommandID > Case 1 > Call ShowPropertiesForm > End Select > End Sub > > Public Sub ShowForm(Optional Modality As _ > frmModality = frmModal) > 'Call frm Form as Modality mode. > frm.Show Modality > End Sub > > Public Sub ShowPropertiesForm(Optional Modality As _ > frmModality = frmModal) > 'Call frmProperties form as Modality mode. > frmProperties.Show Modality > End Sub > > Public Sub ShowDrawingSettingsForm(Optional Modality As frmModality = > frmModal) > frmDrawingSettings.Show Modality > End Sub > >
0 Likes
Message 4 of 5

Anonymous
Not applicable
Sean, These are just kind of rough snippets from my own addin which should point you in the proper direction for adding to the Tools menu. Everything I have posted here is in my ApplicationAddInServer_Activate sub. As you may notice, there are actually 7 seperate Tools menus. This code actually creates a submenu under the Tools menu (with only 1 entry) but you should be able to deduce how to do just a single menu item too, I would think. Bob S. in ApplicationAddInServer_Activate : Set moShadyBobUtilBar2 = oApp.CommandManager.ControlDefinitions.AddButtonDefinition _ ("Settings", "SC_BobUtilsettings", kQueryOnlyCmdType, _ "{}", _ "Display settings for Shady Bob's Inventor Utilities", "Settings", _ oIcon4, oIcon4) ' Find the command bar of the "Tools" pop-up menu. Dim oUIManager As UserInterfaceManager Set oUIManager = oApp.UserInterfaceManager ' Create a command bar of a pop-up type for a flyout. Dim oFlyOutCmdBar As CommandBar Set oFlyOutCmdBar = oUIManager.CommandBars.Add("Bob's Utilities", _ "FlyoutCmdBar", kPopUpCommandBar, "") ' Add 1 button to the fly-out command bar. Call oFlyOutCmdBar.Controls.AddButton(moShadyBobUtilBar2) Dim oMenuPopupCmdBar As CommandBar Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("AppToolsMenu") ' Add the fly-out to the menu pop-up. Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar) Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("AssemblyToolsMenu") ' Add the fly-out to the menu pop-up. Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar) Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("DrawingMangerToolsMenu") ' Add the fly-out to the menu pop-up. Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar) Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("NotebookToolsMenu") ' Add the fly-out to the menu pop-up. Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar) Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("PartFeatureToolsMenu") ' Add the fly-out to the menu pop-up. Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar) Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("PartToolsMenu") ' Add the fly-out to the menu pop-up. Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar) Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("PresentationToolsMenu") ' Add the fly-out to the menu pop-up. Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar) "Sean Dotson" wrote in message news:41c18af4_3@newsprd01... > While this will work I do believe this is the old method. It works in R9 > but will not be supported so may break in future versions. If I'm wrong > please let me know. > > -- > Sean Dotson, PE > www.sdotson.com > Autodesk Inventor Certified Expert > Sidel, Engineering & Manufacturing Manager > > > "Mika Aaltonen" wrote in message > news:41c186a0_3@newsprd01... >> This code works in IV8 and IV9 addin..Add this code to a class module. I >> hope this helps. >> >> Option Explicit >> >> 'Form should be loaded in modality mode. >> Public Enum frmModality >> frmModal = vbModal >> frmModeless = vbModeless >> End Enum >> >> 'Implements for ApplicationAddInServer >> Implements ApplicationAddInServer >> >> 'Public AddInSite As ApplicationAddInSite >> Public AddInSite As ApplicationAddInSite >> 'Public InventorApp As InventorFramework.Application >> Public InventorApp As Inventor.Application >> >> 'Define command. >> Private Command1 As Command >> >> Public Sub ApplicationAddInServer_Activate(ByVal AddInSiteObject As >> Inventor.ApplicationAddInSite, ByVal FirstTime As Boolean) >> 'Inside Activate >> >> 'Save the Add-In site object in a global variable. >> Set AddInSite = AddInSiteObject >> >> 'Save the Invertor Application object. >> Set InventorApp = AddInSite.Application >> >> 'Create the first command. >> Set Command1 = AddInSite.CreateCommand("Property Management", 1, True) >> >> 'Set command to enabled to use command properties. >> Command1.Enabled = True >> >> Set AddInSite = Nothing >> Set InventorApp = Nothing >> Set Command1 = Nothing >> End Sub >> >> 'These subs must be here even there is not any code otherwise compiler >> deletes these subs and >> 'program dosn't work. >> >> 'Public Property Get ApplicationAddInServer_Automation() As >> Inventor.AddInAutomation >> Public Property Get ApplicationAddInServer_Automation() As Object >> 'Inside Automation >> End Property >> >> Public Sub ApplicationAddInServer_Deactivate() >> 'Inside Deactivate >> End Sub >> >> Public Sub ApplicationAddInServer_ExecuteCommand(ByVal CommandID As Long) >> 'If program is executed by clicking it from Tools bar then we will call > it's >> form. >> Select Case CommandID >> Case 1 >> Call ShowPropertiesForm >> End Select >> End Sub >> >> Public Sub ShowForm(Optional Modality As _ >> frmModality = frmModal) >> 'Call frm Form as Modality mode. >> frm.Show Modality >> End Sub >> >> Public Sub ShowPropertiesForm(Optional Modality As _ >> frmModality = frmModal) >> 'Call frmProperties form as Modality mode. >> frmProperties.Show Modality >> End Sub >> >> Public Sub ShowDrawingSettingsForm(Optional Modality As frmModality = >> frmModal) >> frmDrawingSettings.Show Modality >> End Sub >> >> > >
0 Likes
Message 5 of 5

Anonymous
Not applicable
Wonderful, thanks Bob. I'll have a look and let you know how it goes. -- Sean Dotson, PE www.sdotson.com Autodesk Inventor Certified Expert Sidel, Engineering & Manufacturing Manager "Bob S." wrote in message news:41c19432$1_1@newsprd01... > Sean, > > These are just kind of rough snippets from my own addin which should point you in the > proper direction for adding to the Tools menu. Everything I have posted here is in my > ApplicationAddInServer_Activate sub. As you may notice, there are actually 7 seperate > Tools menus. This code actually creates a submenu under the Tools menu (with only 1 entry) > but you should be able to deduce how to do just a single menu item too, I would think. > > Bob S. > > in ApplicationAddInServer_Activate : > > Set moShadyBobUtilBar2 = oApp.CommandManager.ControlDefinitions.AddButtonDefinition _ > ("Settings", "SC_BobUtilsettings", kQueryOnlyCmdType, _ > "{}", _ > "Display settings for Shady Bob's Inventor Utilities", "Settings", _ > oIcon4, oIcon4) > > > > ' Find the command bar of the "Tools" pop-up menu. > Dim oUIManager As UserInterfaceManager > Set oUIManager = oApp.UserInterfaceManager > ' Create a command bar of a pop-up type for a flyout. > Dim oFlyOutCmdBar As CommandBar > Set oFlyOutCmdBar = oUIManager.CommandBars.Add("Bob's Utilities", _ > "FlyoutCmdBar", kPopUpCommandBar, "") > ' Add 1 button to the fly-out command bar. > Call oFlyOutCmdBar.Controls.AddButton(moShadyBobUtilBar2) > > Dim oMenuPopupCmdBar As CommandBar > Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("AppToolsMenu") > ' Add the fly-out to the menu pop-up. > Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar) > Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("AssemblyToolsMenu") > ' Add the fly-out to the menu pop-up. > Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar) > Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("DrawingMangerToolsMenu") > ' Add the fly-out to the menu pop-up. > Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar) > Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("NotebookToolsMenu") > ' Add the fly-out to the menu pop-up. > Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar) > Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("PartFeatureToolsMenu") > ' Add the fly-out to the menu pop-up. > Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar) > Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("PartToolsMenu") > ' Add the fly-out to the menu pop-up. > Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar) > Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("PresentationToolsMenu") > ' Add the fly-out to the menu pop-up. > Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar) > > > "Sean Dotson" wrote in message news:41c18af4_3@newsprd01... > > While this will work I do believe this is the old method. It works in R9 > > but will not be supported so may break in future versions. If I'm wrong > > please let me know. > > > > -- > > Sean Dotson, PE > > www.sdotson.com > > Autodesk Inventor Certified Expert > > Sidel, Engineering & Manufacturing Manager > > > > > > "Mika Aaltonen" wrote in message > > news:41c186a0_3@newsprd01... > >> This code works in IV8 and IV9 addin..Add this code to a class module. I > >> hope this helps. > >> > >> Option Explicit > >> > >> 'Form should be loaded in modality mode. > >> Public Enum frmModality > >> frmModal = vbModal > >> frmModeless = vbModeless > >> End Enum > >> > >> 'Implements for ApplicationAddInServer > >> Implements ApplicationAddInServer > >> > >> 'Public AddInSite As ApplicationAddInSite > >> Public AddInSite As ApplicationAddInSite > >> 'Public InventorApp As InventorFramework.Application > >> Public InventorApp As Inventor.Application > >> > >> 'Define command. > >> Private Command1 As Command > >> > >> Public Sub ApplicationAddInServer_Activate(ByVal AddInSiteObject As > >> Inventor.ApplicationAddInSite, ByVal FirstTime As Boolean) > >> 'Inside Activate > >> > >> 'Save the Add-In site object in a global variable. > >> Set AddInSite = AddInSiteObject > >> > >> 'Save the Invertor Application object. > >> Set InventorApp = AddInSite.Application > >> > >> 'Create the first command. > >> Set Command1 = AddInSite.CreateCommand("Property Management", 1, True) > >> > >> 'Set command to enabled to use command properties. > >> Command1.Enabled = True > >> > >> Set AddInSite = Nothing > >> Set InventorApp = Nothing > >> Set Command1 = Nothing > >> End Sub > >> > >> 'These subs must be here even there is not any code otherwise compiler > >> deletes these subs and > >> 'program dosn't work. > >> > >> 'Public Property Get ApplicationAddInServer_Automation() As > >> Inventor.AddInAutomation > >> Public Property Get ApplicationAddInServer_Automation() As Object > >> 'Inside Automation > >> End Property > >> > >> Public Sub ApplicationAddInServer_Deactivate() > >> 'Inside Deactivate > >> End Sub > >> > >> Public Sub ApplicationAddInServer_ExecuteCommand(ByVal CommandID As Long) > >> 'If program is executed by clicking it from Tools bar then we will call > > it's > >> form. > >> Select Case CommandID > >> Case 1 > >> Call ShowPropertiesForm > >> End Select > >> End Sub > >> > >> Public Sub ShowForm(Optional Modality As _ > >> frmModality = frmModal) > >> 'Call frm Form as Modality mode. > >> frm.Show Modality > >> End Sub > >> > >> Public Sub ShowPropertiesForm(Optional Modality As _ > >> frmModality = frmModal) > >> 'Call frmProperties form as Modality mode. > >> frmProperties.Show Modality > >> End Sub > >> > >> Public Sub ShowDrawingSettingsForm(Optional Modality As frmModality = > >> frmModal) > >> frmDrawingSettings.Show Modality > >> End Sub > >> > >> > > > > > >
0 Likes