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; // TODO: Add ApplicationAddInServer.Activate implementation. // e.g. event initialization, command creation etc. int largeIconSize = 0; if (m_inventorApplication.UserInterfaceManager.InterfaceStyle == InterfaceStyleEnum.kRibbonInterface) { largeIconSize = 32; } else { largeIconSize = 24; } ControlDefinitions controlDefs = m_inventorApplication.CommandManager.ControlDefinitions; stdole.IPictureDisp smallPicture1 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon1.ico").ToBitmap()); stdole.IPictureDisp largePicture1 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon1.ico").ToBitmap()); m_TreeViewBrowser = controlDefs.AddButtonDefinition("HierarchyPane", "BrowserSample:HierarchyPane", CommandTypesEnum.kNonShapeEditCmdType, m_ClientId,null ,null , smallPicture1, largePicture1); m_TreeViewBrowser.OnExecute+= new ButtonDefinitionSink_OnExecuteEventHandler(m_TreeViewBrowser_OnExecute); stdole.IPictureDisp smallPicture2 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon2.ico").ToBitmap()); stdole.IPictureDisp largePicture2 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon2.ico").ToBitmap()); m_ActiveXBrowser = controlDefs.AddButtonDefinition("ActiveXPane", "BrowserSample:ActiveXPane", CommandTypesEnum.kNonShapeEditCmdType, m_ClientId, null ,null , smallPicture2, largePicture2); m_ActiveXBrowser.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(m_ActiveXBrowser_OnExecute); stdole.IPictureDisp smallPicture3 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon3.ico").ToBitmap()); stdole.IPictureDisp largePicture3 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon3.ico").ToBitmap()); m_DoBrowserEvents = controlDefs.AddButtonDefinition("DoBrowserEvents", "BrowserSample:DoBrowserEvents", CommandTypesEnum.kNonShapeEditCmdType, m_ClientId,null ,null , smallPicture3, largePicture3); m_DoBrowserEvents.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(m_DoBrowserEvents_OnExecute); // Get the assembly ribbon. Inventor.Ribbon partRibbon = m_inventorApplication.UserInterfaceManager.Ribbons["Part"]; // Get the "Part" tab. Inventor.RibbonTab partTab = partRibbon.RibbonTabs[1]; Inventor.RibbonPanel partPanel = partTab.RibbonPanels[1]; partPanel.CommandControls.AddButton(m_TreeViewBrowser, true); partPanel.CommandControls.AddButton(m_DoBrowserEvents); partPanel.CommandControls.AddButton(m_ActiveXBrowser); }
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime) { m_inventorApplication = addInSiteObject.Application; m_buttonDefinition = m_inventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition( "Reference Key Manager", "Adam.ReferenceKeyManager", CommandTypesEnum.kNonShapeEditCmdType); m_buttonDefinition.AutoAddToGUI(); m_buttonDefinition.OnExecute += M_buttonDefinition_OnExecute; }
public void Deactivate() { m_buttonDefinition.OnExecute -= M_buttonDefinition_OnExecute; m_buttonDefinition = null; m_inventorApplication = null; GC.Collect(); GC.WaitForPendingFinalizers(); }
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; // TODO: Add ApplicationAddInServer.Activate implementation. // e.g. event initialization, command creation etc. int largeIconSize = 0; if (m_inventorApplication.UserInterfaceManager.InterfaceStyle == InterfaceStyleEnum.kRibbonInterface) { largeIconSize = 32; } else { largeIconSize = 24; } ControlDefinitions controlDefs = m_inventorApplication.CommandManager.ControlDefinitions; stdole.IPictureDisp smallPicture1 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon1.ico").ToBitmap()); stdole.IPictureDisp largePicture1 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon1.ico").ToBitmap()); m_TreeViewBrowser = controlDefs.AddButtonDefinition("HierarchyPane", "BrowserSample:HierarchyPane", CommandTypesEnum.kNonShapeEditCmdType, m_ClientId, null, null, smallPicture1, largePicture1); m_TreeViewBrowser.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(m_TreeViewBrowser_OnExecute); stdole.IPictureDisp smallPicture2 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon2.ico").ToBitmap()); stdole.IPictureDisp largePicture2 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon2.ico").ToBitmap()); m_ActiveXBrowser = controlDefs.AddButtonDefinition("ActiveXPane", "BrowserSample:ActiveXPane", CommandTypesEnum.kNonShapeEditCmdType, m_ClientId, null, null, smallPicture2, largePicture2); m_ActiveXBrowser.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(m_ActiveXBrowser_OnExecute); stdole.IPictureDisp smallPicture3 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon3.ico").ToBitmap()); stdole.IPictureDisp largePicture3 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon3.ico").ToBitmap()); m_DoBrowserEvents = controlDefs.AddButtonDefinition("DoBrowserEvents", "BrowserSample:DoBrowserEvents", CommandTypesEnum.kNonShapeEditCmdType, m_ClientId, null, null, smallPicture3, largePicture3); m_DoBrowserEvents.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(m_DoBrowserEvents_OnExecute); // Get the assembly ribbon. Inventor.Ribbon partRibbon = m_inventorApplication.UserInterfaceManager.Ribbons["Part"]; // Get the "Part" tab. Inventor.RibbonTab partTab = partRibbon.RibbonTabs[1]; Inventor.RibbonPanel partPanel = partTab.RibbonPanels[1]; partPanel.CommandControls.AddButton(m_TreeViewBrowser, true); partPanel.CommandControls.AddButton(m_DoBrowserEvents); partPanel.CommandControls.AddButton(m_ActiveXBrowser); }
public void Deactivate() { // This method is called by Inventor when the AddIn is unloaded. // The AddIn will be unloaded either manually by the user or // when the Inventor session is terminated // TODO: Add ApplicationAddInServer.Deactivate implementation // Release objects. m_inventorApplication = null; testButtonDefinition.OnExecute -= testButtonDefinition_OnExecute; testButtonDefinition = null; GC.Collect(); GC.WaitForPendingFinalizers(); }
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; // TODO: Add ApplicationAddInServer.Activate implementation. // e.g. event initialization, command creation etc. var cmdMgr = m_inventorApplication.CommandManager; m_btnDef = cmdMgr.ControlDefinitions.AddButtonDefinition( "ShowWpfDialog", "ShowWpfDialog", CommandTypesEnum.kQueryOnlyCmdType); m_btnDef.OnExecute += ctrlDef_OnExecute; m_btnDef.AutoAddToGUI(); }
/// <summary> /// Function to simplify the creation of a button definition. The big advantage /// to using this function is that you don't have to deal with converting images /// but instead just reference a folder on disk where this routine reads the images. /// </summary> /// <param name="DisplayName"> /// The name of the command as it will be displayed on the button. /// </param> /// <param name="InternalName"> /// The internal name of the command. This needs to be unique with respect to ALL other /// commands. It's best to incorporate a company name to help with uniqueness. /// </param> /// <param name="ToolTip"> /// The tooltip that will be used for the command. /// /// This is optional and the display name will be used as the /// tooltip if no tooltip is specified. Like in the DisplayName argument, you can use /// returns to force line breaks. /// </param> /// <param name="IconFolder"> /// The folder that contains the icon files. This can be a full path or a path that is /// relative to the location of the add-in dll. The folder should contain the files /// 16x16.png and 32x32.png. Each command will have its own folder so they can have /// their own icons. /// /// This is optional and if no icon is specified then no icon will be displayed on the /// button and it will be only text. /// </param> /// <returns> /// Returns the newly created button definition or Nothing in case of failure. /// </returns> public static Inventor.ButtonDefinition CreateButtonDefinition(string DisplayName, string InternalName, string ToolTip = "", string IconFolder = "") { // Check to see if a command already exists is the specified internal name. Inventor.ButtonDefinition testDef = null; try { testDef = (Inventor.ButtonDefinition)Globals.invApp.CommandManager.ControlDefinitions[InternalName]; } catch (Exception ex) { } if (!(testDef == null)) { MessageBox.Show("Error when loading the add-in \"My_CSharp_AddIn\". A command already exists with the same internal name. Each add-in must have a unique internal name. Change the internal name in the call to CreateButtonDefinition.", "CSharp Inventor Add-In Template"); return(null); } // Check to see if the provided folder is a full or relative path. if (!string.IsNullOrEmpty(IconFolder)) { if (!System.IO.Directory.Exists(IconFolder)) { // The folder provided doesn't exist, so assume it is a relative path and // build up the full path. string dllPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); IconFolder = System.IO.Path.Combine(dllPath, IconFolder); } } // Get the images from the specified icon folder. stdole.IPictureDisp iPicDisp16x16 = null; stdole.IPictureDisp iPicDisp32x32 = null; if (!string.IsNullOrEmpty(IconFolder)) { if (System.IO.Directory.Exists(IconFolder)) { string filename16x16 = System.IO.Path.Combine(IconFolder, "16x16.png"); string filename32x32 = System.IO.Path.Combine(IconFolder, "32x32.png"); if (System.IO.File.Exists(filename16x16)) { try { System.Drawing.Bitmap image16x16 = new System.Drawing.Bitmap(filename16x16); iPicDisp16x16 = ConvertImage.ConvertImageToIPictureDisp(image16x16); } catch (Exception ex) { MessageBox.Show("Unable to load the 16x16.png image from \"" + IconFolder + "\"." + System.Environment.NewLine + "No small icon will be used.", "Error Loading Icon"); } } else { MessageBox.Show("The icon for the small button does not exist: \"" + filename16x16 + "\"." + System.Environment.NewLine + "No small icon will be used.", "Error Loading Icon"); } if (System.IO.File.Exists(filename32x32)) { try { System.Drawing.Bitmap image32x32 = new System.Drawing.Bitmap(filename32x32); iPicDisp32x32 = ConvertImage.ConvertImageToIPictureDisp(image32x32); } catch (Exception ex) { MessageBox.Show("Unable to load the 32x32.png image from \"" + IconFolder + "\"." + System.Environment.NewLine + "No large icon will be used.", "Error Loading Icon"); } } else { MessageBox.Show("The icon for the large button does not exist: \"" + filename32x32 + "\"." + System.Environment.NewLine + "No large icon will be used.", "Error Loading Icon"); } } } try { // Get the ControlDefinitions collection. ControlDefinitions controlDefs = Globals.invApp.CommandManager.ControlDefinitions; // Create the command defintion. ButtonDefinition btnDef = controlDefs.AddButtonDefinition(DisplayName, InternalName, Inventor.CommandTypesEnum.kShapeEditCmdType, Globals.g_addInClientID, "", ToolTip, iPicDisp16x16, iPicDisp32x32); return(btnDef); } catch (Exception ex) { return(null); } }
public void Deactivate() { // This method is called by Inventor when the AddIn is unloaded. // The AddIn will be unloaded either manually by the user or // when the Inventor session is terminated // TODO: Add ApplicationAddInServer.Deactivate implementation // Release objects. Marshal.ReleaseComObject(m_inventorApplication); m_inventorApplication = null; Marshal.ReleaseComObject(buttonDefinition); buttonDefinition = null; GC.WaitForPendingFinalizers(); GC.Collect(); }
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; // TODO: Add ApplicationAddInServer.Activate implementation. // e.g. event initialization, command creation etc. strAddInGUID = "{" + ((GuidAttribute)System.Attribute.GetCustomAttribute(typeof(StandardAddInServer), typeof(GuidAttribute))).Value + "}"; //���õ��û���������������� UserInterfaceManager userInterfaceManager; userInterfaceManager = m_inventorApplication.UserInterfaceManager; //����buttonDefinition���� Icon Icon1 = new Icon(this.GetType(), "Icon1.ico"); stdole.IPictureDisp standardIconIPictureDisp; standardIconIPictureDisp = (stdole.IPictureDisp)Support.IconToIPicture(Icon1); buttonDefinition = m_inventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition( "Display Name", "invrSampleCommand", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "Description Text", "Tooltip", standardIconIPictureDisp, standardIconIPictureDisp, ButtonDisplayEnum.kDisplayTextInLearningMode); //Ϊ��ť������� buttonDefinition.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(ButtonDefinition_OnExecute); //����Դ�ļ��м���ͼ�겢������ť���� buttonDefinition1 = m_inventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition( "Button 1", "invrSampleCommand1", CommandTypesEnum.kQueryOnlyCmdType, strAddInGUID, "This is button 1.", "Button 1", standardIconIPictureDisp, standardIconIPictureDisp, ButtonDisplayEnum.kDisplayTextInLearningMode); buttonDefinition1.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(buttonDefinition1_OnExecute); //�ٴ���������ť���壬һ����ͼ�꣬��һ��û��ͼ�� Icon Icon2 = new Icon(this.GetType(), "Icon2.ico"); standardIconIPictureDisp = (stdole.IPictureDisp)Support.IconToIPicture(Icon2); buttonDefinition2 = m_inventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition( "Button 2", "invrSampleCommand2", CommandTypesEnum.kQueryOnlyCmdType, strAddInGUID, "This is button 2.", "Button 2", standardIconIPictureDisp, standardIconIPictureDisp, ButtonDisplayEnum.kDisplayTextInLearningMode); buttonDefinition2.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(buttonDefinition2_OnExecute); buttonDefinition3 = m_inventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition( "Button 3", "invrSampleCommand3", CommandTypesEnum.kQueryOnlyCmdType, strAddInGUID, "This is button 3.", "Button 3", System.Type.Missing, System.Type.Missing, ButtonDisplayEnum.kDisplayTextInLearningMode); buttonDefinition3.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(ButtonDefinition3_OnExecute); if (firstTime) { //������������ CommandBar commandBar; commandBar = userInterfaceManager.CommandBars.Add("Test Bar", "intTestBar", CommandBarTypeEnum.kRegularCommandBar, strAddInGUID); //����ť�ؼ���ӵ��������� commandBar.Controls.AddButton(buttonDefinition, 0); commandBar.Visible = true; //���ҵ�װ�乤���� CommandBar asmCmdBar; asmCmdBar = userInterfaceManager.CommandBars["AMxAssemblyPanelCmdBar"]; //������������ӿؼ� asmCmdBar.Controls.AddButton(buttonDefinition, 0); //���������� Inventor.Environment partEnv; partEnv = userInterfaceManager.Environments["PMxPartEnvironment"]; //���õ�PanelBar��������� PanelBar panelBar; panelBar = partEnv.PanelBar; //����������ӵ����������������б��� panelBar.CommandBarList.Add(commandBar); //�������˵���ʹ�õ������� CommandBar partMenuCB; partMenuCB = partEnv.DefaultMenuBar; //�����������͵������� CommandBar flyOutCmdBar; flyOutCmdBar = userInterfaceManager.CommandBars.Add("More Commands", "FlyoutCmdBar", CommandBarTypeEnum.kPopUpCommandBar, strAddInGUID); //�ڵ��������������������ť flyOutCmdBar.Controls.AddButton(buttonDefinition2, 0); flyOutCmdBar.Controls.AddButton(buttonDefinition3, 0); //Ϊ�����˵������������͵������� CommandBar menuPopupCmdBar; menuPopupCmdBar = userInterfaceManager.CommandBars.Add("Test", "MenuPopupCmdBar", CommandBarTypeEnum.kPopUpCommandBar, strAddInGUID); //�ڵ����˵���������� menuPopupCmdBar.Controls.AddButton(buttonDefinition1, 0); //��������������ӵ������˵��� menuPopupCmdBar.Controls.AddPopup(flyOutCmdBar, 0); //��á��������ؼ������к� int helpIndex; helpIndex = partMenuCB.Controls["AppHelpMenu"].index; //�������˵���ӵ�����˵��С��������ؼ�֮ǰ partMenuCB.Controls.AddPopup(menuPopupCmdBar, helpIndex); } }
//Loads With Inventor 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; // TODO: Add ApplicationAddInServer.Activate implementation. // e.g. event initialization, command creation etc. System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); string[] resources = assembly.GetManifestResourceNames(); Icon oIcon32 = new Icon(PowerViewsAndGroups.Properties.Resources.Icon2, PowerViewsAndGroups.Properties.Resources.Icon2.Width, PowerViewsAndGroups.Properties.Resources.Icon2.Height); Icon oIcon16 = new Icon(PowerViewsAndGroups.Properties.Resources.Icon1, PowerViewsAndGroups.Properties.Resources.Icon1.Width, PowerViewsAndGroups.Properties.Resources.Icon1.Height); object oIPictureDisp32 = AxHostConverter.ImageToPictureDisp(oIcon32.ToBitmap()); object oIPictureDisp16 = AxHostConverter.ImageToPictureDisp(oIcon16.ToBitmap()); try { _buttonDef1 = m_inventorApplication.CommandManager.ControlDefinitions[ControlDefinitions] as ButtonDefinition; } catch (Exception) { _buttonDef1 = m_inventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition(DisplayName, InternalName, CommandTypesEnum.kUpdateWithReferencesCmdType, addInGuid, DescriptionText, ToolTipText, oIPictureDisp16, oIPictureDisp32, ButtonDisplayEnum.kDisplayTextInLearningMode); CommandCategory cmdCat = m_inventorApplication.CommandManager.CommandCategories.Add(DescriptionText, InternalName, addInGuid); cmdCat.Add(_buttonDef1); } if (firstTime) { try { if (m_inventorApplication.UserInterfaceManager.InterfaceStyle == InterfaceStyleEnum.kRibbonInterface) { Ribbon ribbon = m_inventorApplication.UserInterfaceManager.Ribbons[ModelType]; RibbonTab tab = ribbon.RibbonTabs[ID_Tab]; try { RibbonPanel panel = tab.RibbonPanels.Add(DescriptionText, RibbonInternalName, addInGuid, "", false); CommandControl control1 = panel.CommandControls.AddButton(_buttonDef1, true, true, "", false); } catch //(Exception ex) { } } else { CommandBar m_CommandBar = m_inventorApplication.UserInterfaceManager.CommandBars[CommandBarsName]; m_CommandBar.Controls.AddButton(_buttonDef1, 0); } } catch { CommandBar oCommandBar = m_inventorApplication.UserInterfaceManager.CommandBars[CommandBarsName]; oCommandBar.Controls.AddButton(_buttonDef1, 0); } } _buttonDef1.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(_buttonDef1_OnExecute); MessageBox.Show("PGroups"); }