/// <summary> /// modifies Drawing ribbon by adding two buttons used by the add-in /// </summary> private void modifyRibbon() { //get Command manager cmdMan = m_inventorApplication.CommandManager; //get control definitions ctrlDefs = cmdMan.ControlDefinitions; //define command category for add-in's buttons cmdCat = cmdMan.CommandCategories.Add("Auto-Breaker", "Autodesk:CmdCategory:AutoBreaker", addInGuid); //get 'Drawing' ribbon drawingRibbon = m_inventorApplication.UserInterfaceManager.Ribbons["Drawing"]; //get 'Place Views' tab from 'Drawing' ribbon placeTab = drawingRibbon.RibbonTabs["id_TabPlaceViews"]; //define 'Apply break' button applyButton = ctrlDefs.AddButtonDefinition("Apply!", "Autodesk:AutoBreaker:ApplyButton", CommandTypesEnum.kQueryOnlyCmdType, addInGuid, "auto-break description", "auto-break tooltip", plus16obj, plus128obj, ButtonDisplayEnum.kAlwaysDisplayText); applyButton.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(customAction); cmdCat.Add(applyButton); //define 'Settings' button settingsButton = ctrlDefs.AddButtonDefinition("Settings", "Autodesk:AutoBreaker:SettingsButton", CommandTypesEnum.kQueryOnlyCmdType, addInGuid, "auto-breaker settings description", "auto-break settings tool-tip", gear16obj, gear128obj, ButtonDisplayEnum.kAlwaysDisplayText); settingsButton.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(settingsClick); cmdCat.Add(settingsButton); //define panel in 'Place Views' tab panel = placeTab.RibbonPanels.Add("Auto-Breaker", "Autodesk:AutoBreaker:AutoBreakerPanel", addInGuid); controlApplyBreak = panel.CommandControls.AddButton(applyButton, true, true); controlSettingsBreak = panel.CommandControls.AddButton(settingsButton, true, true); }
public Button(string DisplayName, string internalName, string clientId, string description, string tooltip, Icon standarticon, Icon largeIcon, string catName = "CSharp") { try { stdole.IPictureDisp standartIconIPictureDisp; standartIconIPictureDisp = OleCreateConverter.ImageToPictureDisp(standarticon.ToBitmap()); stdole.IPictureDisp largeIconIPictureDisp; largeIconIPictureDisp = OleCreateConverter.ImageToPictureDisp(largeIcon.ToBitmap()); m_buttonDefinition = m_inventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition(DisplayName, "Autodesk:Macros:" + internalName, CommandTypesEnum.kNonShapeEditCmdType, clientId, description, tooltip, standartIconIPictureDisp, largeIconIPictureDisp, ButtonDisplayEnum.kDisplayTextInLearningMode); m_buttonDefinition.Enabled = true; ButtonDefinition_OnExecuteEventDelegate = new ButtonDefinitionSink_OnExecuteEventHandler(ButtonDefinition_OnExecute); m_buttonDefinition.OnExecute += ButtonDefinition_OnExecuteEventDelegate; if (catName != "") { CommandCategory cat = u.get <CommandCategory>(m_inventorApplication.CommandManager.CommandCategories, c => c.DisplayName == catName) ?? m_inventorApplication.CommandManager.CommandCategories.Add(catName, "Autodesk:Macros:" + catName); cat.Add(m_buttonDefinition); } } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } }
private ButtonDefinition GetShowTextButton(string addinId, Application application) { CommandCategory slotCmdCategory = application.CommandManager.CommandCategories.Add("Slot", "Autodesk:YourAddIn:ShowTextCmd", addinId); var btn = new TestButton(application, addinId); slotCmdCategory.Add(btn.ButtonDefinition); return(btn.ButtonDefinition); }
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. ControlDefinitions oCtrlDefs = m_inventorApplication.CommandManager.ControlDefinitions; System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); string[] resources = assembly.GetManifestResourceNames(); System.IO.Stream oStream1 = assembly.GetManifestResourceStream("ZeroRibbon.resources.Icon1.ico"); System.IO.Stream oStream2 = assembly.GetManifestResourceStream("ZeroRibbon.resources.Icon2.ico"); System.Drawing.Icon oIcon1 = new System.Drawing.Icon(oStream1); System.Drawing.Icon oIcon2 = new System.Drawing.Icon(oStream2); object oIPictureDisp1 = AxHostConverter.ImageToPictureDisp(oIcon1.ToBitmap()); object oIPictureDisp2 = AxHostConverter.ImageToPictureDisp(oIcon2.ToBitmap()); try { Zero_GetStarted_LaunchPanel_ButtonDef = oCtrlDefs["Autodesk:ZeroRibbon:ButtonDef1"] as ButtonDefinition; Zero_GetStarted_NewPanel_ButtonDef = oCtrlDefs["Autodesk:ZeroRibbon:ButtonDef2"] as ButtonDefinition; } catch (Exception ex) { Zero_GetStarted_LaunchPanel_ButtonDef = oCtrlDefs.AddButtonDefinition("Ribbon Demo1", "Autodesk:ZeroRibbon:ButtonDef1", CommandTypesEnum.kEditMaskCmdType, addInGuid, "Ribbon Demo", "Ribbon Demo Description", oIPictureDisp1, oIPictureDisp1, ButtonDisplayEnum.kDisplayTextInLearningMode); Zero_GetStarted_NewPanel_ButtonDef = oCtrlDefs.AddButtonDefinition("Ribbon Demo2", "Autodesk:ZeroRibbon:ButtonDef2", CommandTypesEnum.kEditMaskCmdType, addInGuid, "Ribbon Demo", "Ribbon Demo Description", oIPictureDisp2, oIPictureDisp2, ButtonDisplayEnum.kDisplayTextInLearningMode); CommandCategory cmdCat = m_inventorApplication.CommandManager.CommandCategories.Add("RibbonDemo C#", "Autodesk:CmdCategory:RibbonDemoC#", addInGuid); cmdCat.Add(Zero_GetStarted_LaunchPanel_ButtonDef); cmdCat.Add(Zero_GetStarted_NewPanel_ButtonDef); } Ribbon ribbon = m_inventorApplication.UserInterfaceManager.Ribbons["ZeroDoc"]; RibbonTab tab = ribbon.RibbonTabs["id_GetStarted"]; RibbonPanel built_panel = tab.RibbonPanels["id_Panel_Launch"]; built_panel.CommandControls.AddButton(Zero_GetStarted_LaunchPanel_ButtonDef, true); RibbonPanel panel1 = tab.RibbonPanels.Add("Ribbon Demo", "Autodesk:RibbonDemoC#:Panel1", addInGuid, "", false); panel1.CommandControls.AddButton(Zero_GetStarted_NewPanel_ButtonDef, true); Zero_GetStarted_LaunchPanel_ButtonDef.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(Zero_GetStarted_LaunchPanel_ButtonDef_OnExecute); Zero_GetStarted_NewPanel_ButtonDef.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(Zero_GetStarted_NewPanel_ButtonDef_OnExecute); }
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime) { try { //the Activate 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; InvAddIn.Button.InventorApplication = m_inventorApplication; //initialize event delegates m_userInterfaceEvents = m_inventorApplication.UserInterfaceManager.UserInterfaceEvents; UserInterfaceEventsSink_OnResetCommandBarsEventDelegate = new UserInterfaceEventsSink_OnResetCommandBarsEventHandler(UserInterfaceEvents_OnResetCommandBars); m_userInterfaceEvents.OnResetCommandBars += UserInterfaceEventsSink_OnResetCommandBarsEventDelegate; UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate = new UserInterfaceEventsSink_OnResetEnvironmentsEventHandler(UserInterfaceEvents_OnResetEnvironments); m_userInterfaceEvents.OnResetEnvironments += UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate; UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate = new UserInterfaceEventsSink_OnResetRibbonInterfaceEventHandler(UserInterfaceEvents_OnResetRibbonInterface); m_userInterfaceEvents.OnResetRibbonInterface += UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate; //load image icons for UI items IPictureDisp createMasterMIcon = AxHostConverter.ImageToPictureDisp(Resources.CreateMasterM.ToBitmap()); IPictureDisp createMasterMICON = AxHostConverter.ImageToPictureDisp(Resources.CreateMasterM.ToBitmap()); IPictureDisp helpIcon = AxHostConverter.ImageToPictureDisp(Resources.icon1.ToBitmap()); IPictureDisp helpICON = AxHostConverter.ImageToPictureDisp(Resources.icon1.ToBitmap()); //retrieve the GUID for this class GuidAttribute addInCLSID; addInCLSID = (GuidAttribute)GuidAttribute.GetCustomAttribute(typeof(StandardAddInServer), typeof(GuidAttribute)); string addInCLSIDString; addInCLSIDString = "{" + addInCLSID.Value + "}"; //create buttons ButtON = new BenjaminButton( "MasterModel", "MasterModel:StandardAddInServer:BenjaminBUTTON", CommandTypesEnum.kShapeEditCmdType, addInCLSIDString, "Create a Master Model File", "keep the model simple", createMasterMIcon, createMasterMICON, ButtonDisplayEnum.kDisplayTextInLearningMode, false); //ButtON.HeySherlock = (PartDocument) m_inventorApplication.ActiveDocument; Help = new BenjaminButton( "How to", "Help:StandardAddInServer:BenjaminBUTTON", CommandTypesEnum.kShapeEditCmdType, addInCLSIDString, "Help Creating a Master Model File", "keep the model simple", helpIcon, helpICON, ButtonDisplayEnum.kDisplayTextInLearningMode, true); //create the command category CommandCategory MasterMCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("Master Model", "MasterModel:StandardAddInServer:BenjaminBUTTON", addInCLSIDString); MasterMCmdCategory.Add(ButtON.ButtonDefinition); MasterMCmdCategory.Add(Help.ButtonDefinition); if (firstTime == true) { //access user interface manager UserInterfaceManager userInterfaceManager; userInterfaceManager = m_inventorApplication.UserInterfaceManager; InterfaceStyleEnum interfaceStyle; interfaceStyle = userInterfaceManager.InterfaceStyle; //create the UI for classic interface if (interfaceStyle == InterfaceStyleEnum.kClassicInterface) { //create toolbar CommandBar MasterCommander; MasterCommander = userInterfaceManager.CommandBars.Add("Master Model", "MasterModel:StandardAddInServer:BenjaminBUTTONToolbar", CommandBarTypeEnum.kRegularCommandBar, addInCLSIDString); //add buttons to toolbar MasterCommander.Controls.AddButton(ButtON.ButtonDefinition, 0); MasterCommander.Controls.AddButton(Help.ButtonDefinition, 0); //Get the 2d sketch environment base object Inventor.Environment partToolEnvironment; partToolEnvironment = userInterfaceManager.Environments["PMxPartSkEnvironment"]; //make this command bar accessible in the panel menu for the Tool environment. partToolEnvironment.PanelBar.CommandBarList.Add(MasterCommander); } //create the UI for ribbon interface else { //get the ribbon associated with part document Inventor.Ribbons ribbons; ribbons = userInterfaceManager.Ribbons; Inventor.Ribbon partRibbon; partRibbon = ribbons["Part"]; //get the tabs associated with part ribbon RibbonTabs ribbonTabs; ribbonTabs = partRibbon.RibbonTabs; //get the Tool tab RibbonTab partToolRibbonTab; partToolRibbonTab = ribbonTabs["id_TabTools"]; //create a new panel with the tab RibbonPanels ribbonPanels; ribbonPanels = partToolRibbonTab.RibbonPanels; partToolMasterRibbonPanel = ribbonPanels.Add("Master Model", "MasterModel:StandardAddInServer:BenjaminBUTTONRibbonPanel", "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "", false); //add controls to the MasterModel panel CommandControls partToolMasterRibbonPanelCtrls; partToolMasterRibbonPanelCtrls = partToolMasterRibbonPanel.CommandControls; //add the buttons to the ribbon panel CommandControl MasterMoRiPaCtrl; MasterMoRiPaCtrl = partToolMasterRibbonPanelCtrls.AddButton(ButtON.ButtonDefinition, false, true, "", false); MasterMoRiPaCtrl = partToolMasterRibbonPanelCtrls.AddButton(Help.ButtonDefinition, false, true, "", false); } } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime) { try { SetupDynamoPaths(); inventorApplication = addInSiteObject.Application; PersistenceManager.InventorApplication = inventorApplication; userInterfaceManager = inventorApplication.UserInterfaceManager; //initialize event delegates userInterfaceEvents = inventorApplication.UserInterfaceManager.UserInterfaceEvents; UserInterfaceEventsSink_OnResetCommandBarsEventDelegate = new UserInterfaceEventsSink_OnResetCommandBarsEventHandler(UserInterfaceEvents_OnResetCommandBars); userInterfaceEvents.OnResetCommandBars += UserInterfaceEventsSink_OnResetCommandBarsEventDelegate; UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate = new UserInterfaceEventsSink_OnResetEnvironmentsEventHandler(UserInterfaceEvents_OnResetEnvironments); userInterfaceEvents.OnResetEnvironments += UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate; UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate = new UserInterfaceEventsSink_OnResetRibbonInterfaceEventHandler(UserInterfaceEvents_OnResetRibbonInterface); userInterfaceEvents.OnResetRibbonInterface += UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate; appEvents = inventorApplication.ApplicationEvents; appEvents.OnActivateDocument += appEvents_OnActivateDocument; appEvents.OnDeactivateDocument += appEvents_OnDeactivateDocument; Icon dynamoIcon = Resources.logo_square_32x32; //retrieve the GUID for this class GuidAttribute addInCLSID; addInCLSID = (GuidAttribute)GuidAttribute.GetCustomAttribute(this.GetType(), typeof(GuidAttribute)); string addInCLSIDString; addInCLSIDString = "{" + addInCLSID.Value + "}"; dynamoAddinButton = new DynamoInventorAddinButton( buttonDisplayName, buttonInternalName, CommandTypesEnum.kShapeEditCmdType, addInCLSIDString, "Initialize Dynamo.", "Dynamo is a visual programming environment for Inventor.", dynamoIcon, dynamoIcon, ButtonDisplayEnum.kDisplayTextInLearningMode); CommandCategory assemblyUtilitiesCategory = inventorApplication.CommandManager.CommandCategories.Add(commandCategoryDisplayName, commandCategoryInternalName, addInCLSID); assemblyUtilitiesCategory.Add(dynamoAddinButton.ButtonDefinition); if (firstTime == true) { InterfaceStyleEnum interfaceStyle; interfaceStyle = userInterfaceManager.InterfaceStyle; if (interfaceStyle == InterfaceStyleEnum.kClassicInterface) { CommandBar assemblyUtilityCommandBar; assemblyUtilityCommandBar = userInterfaceManager.CommandBars.Add(commandBarDisplayName, commandBarInternalName, CommandBarTypeEnum.kRegularCommandBar, addInCLSID); } else { Inventor.Ribbons ribbons = userInterfaceManager.Ribbons; Inventor.Ribbon assemblyRibbon = ribbons["Assembly"]; RibbonTabs ribbonTabs = assemblyRibbon.RibbonTabs; RibbonTab assemblyRibbonTab = ribbonTabs["id_AddInsTab"]; RibbonPanels ribbonPanels = assemblyRibbonTab.RibbonPanels; assemblyRibbonPanel = ribbonPanels.Add(ribbonPanelDisplayName, ribbonPanelInternalName, "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "", false); CommandControls assemblyRibbonPanelCtrls = assemblyRibbonPanel.CommandControls; CommandControl assemblyCmdBtnCmdCtrl = assemblyRibbonPanelCtrls.AddButton(dynamoAddinButton.ButtonDefinition, true, true, "", false); Inventor.Ribbon partRibbon = ribbons["Part"]; RibbonTabs partRibbonTabs = partRibbon.RibbonTabs; RibbonTab modelRibbonTab = partRibbonTabs["id_AddInsTab"]; RibbonPanels partRibbonPanels = modelRibbonTab.RibbonPanels; partRibbonPanel = partRibbonPanels.Add(ribbonPanelDisplayName, ribbonPanelInternalName, "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "", false); CommandControls partRibbonPanelCtrls = partRibbonPanel.CommandControls; CommandControl partCmdBtnCmdCtrl = partRibbonPanelCtrls.AddButton(dynamoAddinButton.ButtonDefinition, true, true, "", false); Inventor.Ribbon drawingRibbon = ribbons["Drawing"]; RibbonTabs drawingRibbonTabs = drawingRibbon.RibbonTabs; RibbonTab drawingRibbonTab = drawingRibbonTabs["id_AddInsTab"]; RibbonPanels drawingRibbonPanels = drawingRibbonTab.RibbonPanels; drawingRibbonPanel = drawingRibbonPanels.Add(ribbonPanelDisplayName, ribbonPanelInternalName, "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "", false); CommandControls drawingRibbonPanelCtrls = drawingRibbonPanel.CommandControls; CommandControl drawingCmdBtnCmdCtrl = drawingRibbonPanelCtrls.AddButton(dynamoAddinButton.ButtonDefinition, true, true, "", false); } } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime) { try { //the Activate 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; Button.InventorApplication = m_inventorApplication; //initialize event delegates m_userInterfaceEvents = m_inventorApplication.UserInterfaceManager.UserInterfaceEvents; UserInterfaceEventsSink_OnResetCommandBarsEventDelegate = new UserInterfaceEventsSink_OnResetCommandBarsEventHandler(UserInterfaceEvents_OnResetCommandBars); m_userInterfaceEvents.OnResetCommandBars += UserInterfaceEventsSink_OnResetCommandBarsEventDelegate; UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate = new UserInterfaceEventsSink_OnResetEnvironmentsEventHandler(UserInterfaceEvents_OnResetEnvironments); m_userInterfaceEvents.OnResetEnvironments += UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate; UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate = new UserInterfaceEventsSink_OnResetRibbonInterfaceEventHandler(UserInterfaceEvents_OnResetRibbonInterface); m_userInterfaceEvents.OnResetRibbonInterface += UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate; //load image icons for UI items Icon addSlotOptionIcon = new Icon(this.GetType(), "AddSlotOption.ico"); Icon drawSlotIcon = new Icon(this.GetType(), "DrawSlot.ico"); Icon toggleSlotStateIcon = new Icon(this.GetType(), "ToggleSlotState.ico"); //retrieve the GUID for this class GuidAttribute addInCLSID; addInCLSID = (GuidAttribute)GuidAttribute.GetCustomAttribute(typeof(AddInServer), typeof(GuidAttribute)); string addInCLSIDString; addInCLSIDString = "{" + addInCLSID.Value + "}"; //create the comboboxes m_slotWidthComboBoxDefinition = m_inventorApplication.CommandManager.ControlDefinitions.AddComboBoxDefinition("Slot Width", "Autodesk:SimpleAddIn:SlotWidthCboBox", CommandTypesEnum.kShapeEditCmdType, 100, addInCLSIDString, "Slot width", "Slot width", Type.Missing, Type.Missing, ButtonDisplayEnum.kDisplayTextInLearningMode); m_slotHeightComboBoxDefinition = m_inventorApplication.CommandManager.ControlDefinitions.AddComboBoxDefinition("Slot Height", "Autodesk:SimpleAddIn:SlotHeightCboBox", CommandTypesEnum.kShapeEditCmdType, 100, addInCLSIDString, "Slot height", "Slot height", Type.Missing, Type.Missing, ButtonDisplayEnum.kDisplayTextInLearningMode); //add some initial items to the comboboxes m_slotWidthComboBoxDefinition.AddItem("1 cm", 0); m_slotWidthComboBoxDefinition.AddItem("2 cm", 0); m_slotWidthComboBoxDefinition.AddItem("3 cm", 0); m_slotWidthComboBoxDefinition.AddItem("4 cm", 0); m_slotWidthComboBoxDefinition.AddItem("5 cm", 0); m_slotWidthComboBoxDefinition.ListIndex = 1; m_slotWidthComboBoxDefinition.ToolTipText = m_slotWidthComboBoxDefinition.Text; m_slotWidthComboBoxDefinition.DescriptionText = "Slot width: " + m_slotWidthComboBoxDefinition.Text; SlotWidthComboBox_OnSelectEventDelegate = new ComboBoxDefinitionSink_OnSelectEventHandler(SlotWidthComboBox_OnSelect); m_slotWidthComboBoxDefinition.OnSelect += SlotWidthComboBox_OnSelectEventDelegate; m_slotHeightComboBoxDefinition.AddItem("1 cm", 0); m_slotHeightComboBoxDefinition.AddItem("2 cm", 0); m_slotHeightComboBoxDefinition.AddItem("3 cm", 0); m_slotHeightComboBoxDefinition.AddItem("4 cm", 0); m_slotHeightComboBoxDefinition.AddItem("5 cm", 0); m_slotHeightComboBoxDefinition.ListIndex = 1; m_slotHeightComboBoxDefinition.ToolTipText = m_slotHeightComboBoxDefinition.Text; m_slotHeightComboBoxDefinition.DescriptionText = "Slot height: " + m_slotHeightComboBoxDefinition.Text; SlotHeightComboBox_OnSelectEventDelegate = new ComboBoxDefinitionSink_OnSelectEventHandler(SlotHeightComboBox_OnSelect); m_slotHeightComboBoxDefinition.OnSelect += SlotHeightComboBox_OnSelectEventDelegate; //create buttons m_addSlotOptionButton = new AddSlotOptionButton( "Add Slot width/height", "Autodesk:SimpleAddIn:AddSlotOptionCmdBtn", CommandTypesEnum.kShapeEditCmdType, addInCLSIDString, "Adds option for slot width/height", "Add slot option", addSlotOptionIcon, addSlotOptionIcon, ButtonDisplayEnum.kDisplayTextInLearningMode); m_drawSlotButton = new DrawSlotButton( "Draw Slot", "Autodesk:SimpleAddIn:DrawSlotCmdBtn", CommandTypesEnum.kShapeEditCmdType, addInCLSIDString, "Create slot sketch graphics", "Draw Slot", drawSlotIcon, drawSlotIcon, ButtonDisplayEnum.kDisplayTextInLearningMode); m_toggleSlotStateButton = new ToggleSlotStateButton( "Toggle Slot State", "Autodesk:SimpleAddIn:ToggleSlotStateCmdBtn", CommandTypesEnum.kShapeEditCmdType, addInCLSIDString, "Enables/Disables state of slot command", "Toggle Slot State", toggleSlotStateIcon, toggleSlotStateIcon, ButtonDisplayEnum.kDisplayTextInLearningMode); //create the command category CommandCategory slotCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("Slot", "Autodesk:SimpleAddIn:SlotCmdCat", addInCLSIDString); slotCmdCategory.Add(m_slotWidthComboBoxDefinition); slotCmdCategory.Add(m_slotHeightComboBoxDefinition); slotCmdCategory.Add(m_addSlotOptionButton.ButtonDefinition); slotCmdCategory.Add(m_drawSlotButton.ButtonDefinition); slotCmdCategory.Add(m_toggleSlotStateButton.ButtonDefinition); if (firstTime == true) { //access user interface manager UserInterfaceManager userInterfaceManager; userInterfaceManager = m_inventorApplication.UserInterfaceManager; InterfaceStyleEnum interfaceStyle; interfaceStyle = userInterfaceManager.InterfaceStyle; //create the UI for classic interface if (interfaceStyle == InterfaceStyleEnum.kClassicInterface) { //create toolbar CommandBar slotCommandBar; slotCommandBar = userInterfaceManager.CommandBars.Add("Slot", "Autodesk:SimpleAddIn:SlotToolbar", CommandBarTypeEnum.kRegularCommandBar, addInCLSIDString); //add comboboxes to toolbar slotCommandBar.Controls.AddComboBox(m_slotWidthComboBoxDefinition, 0); slotCommandBar.Controls.AddComboBox(m_slotHeightComboBoxDefinition, 0); //add buttons to toolbar slotCommandBar.Controls.AddButton(m_addSlotOptionButton.ButtonDefinition, 0); slotCommandBar.Controls.AddButton(m_drawSlotButton.ButtonDefinition, 0); slotCommandBar.Controls.AddButton(m_toggleSlotStateButton.ButtonDefinition, 0); //Get the 2d sketch environment base object Inventor.Environment partSketchEnvironment; partSketchEnvironment = userInterfaceManager.Environments["PMxPartSketchEnvironment"]; //make this command bar accessible in the panel menu for the 2d sketch environment. partSketchEnvironment.PanelBar.CommandBarList.Add(slotCommandBar); } //create the UI for ribbon interface else { //get the ribbon associated with part document Inventor.Ribbons ribbons; ribbons = userInterfaceManager.Ribbons; Inventor.Ribbon partRibbon; partRibbon = ribbons["Part"]; //get the tabls associated with part ribbon RibbonTabs ribbonTabs; ribbonTabs = partRibbon.RibbonTabs; RibbonTab partSketchRibbonTab; partSketchRibbonTab = ribbonTabs["id_TabSketch"]; //create a new panel with the tab RibbonPanels ribbonPanels; ribbonPanels = partSketchRibbonTab.RibbonPanels; m_partSketchSlotRibbonPanel = ribbonPanels.Add("Slot", "Autodesk:SimpleAddIn:SlotRibbonPanel", "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "", false); //add controls to the slot panel CommandControls partSketchSlotRibbonPanelCtrls; partSketchSlotRibbonPanelCtrls = m_partSketchSlotRibbonPanel.CommandControls; //add the combo boxes to the ribbon panel CommandControl slotWidthCmdCboBoxCmdCtrl; slotWidthCmdCboBoxCmdCtrl = partSketchSlotRibbonPanelCtrls.AddComboBox(m_slotWidthComboBoxDefinition, "", false); CommandControl slotHeightCmdCboBoxCmdCtrl; slotHeightCmdCboBoxCmdCtrl = partSketchSlotRibbonPanelCtrls.AddComboBox(m_slotHeightComboBoxDefinition, "", false); //add the buttons to the ribbon panel CommandControl drawSlotCmdBtnCmdCtrl; drawSlotCmdBtnCmdCtrl = partSketchSlotRibbonPanelCtrls.AddButton(m_drawSlotButton.ButtonDefinition, false, true, "", false); CommandControl slotOptionCmdBtnCmdCtrl; slotOptionCmdBtnCmdCtrl = partSketchSlotRibbonPanelCtrls.AddButton(m_addSlotOptionButton.ButtonDefinition, false, true, "", false); CommandControl toggleSlotStateCmdBtnCmdCtrl; toggleSlotStateCmdBtnCmdCtrl = partSketchSlotRibbonPanelCtrls.AddButton(m_toggleSlotStateButton.ButtonDefinition, false, true, "", false); } } MessageBox.Show("To access the commands of the sample addin, activate a 2d sketch of a part \n document and select the \"AddInSlot\" toolbar within the panel menu"); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime) { // authorization procedure _isAuthorize = true; if (_isAuthorize) { // Initialize AddIn members. _app = addInSiteObject.Application; #region UI INIT Image exportImg = TemplateAdskInventor.Properties.Resources.Button; _exportPict = ImageConversion.ImageToPictureDisp(exportImg); // get command manager _cmdMan = _app.CommandManager; // defne comand catagory for addin buttons _cmdCat = _cmdMan.CommandCategories.Add( _panelDisplayName, "flecheria:CmdCategory:TemplateAdskInventor", _addInGuid); ControlDefinitions ctrlDefs = _app.CommandManager.ControlDefinitions; try { _exportBtnDef = ctrlDefs["flecheria:TemplateAdskInventor:TestButton"] as ButtonDefinition; } catch (Exception ex) { #region BUTTON CREATION ExportButton exportBtn = new ExportButton(_app, "Export Obj", "flecheria:TemplateAdskInventor:ExportObj", CommandTypesEnum.kQueryOnlyCmdType, _addInGuid, "Export Obj with data", "Export Obj with data and tree information", _exportPict, _exportPict, ButtonDisplayEnum.kAlwaysDisplayText); _exportBtnDef = exportBtn.ButtonDefinition; _cmdCat.Add(_exportBtnDef); #endregion Debug.WriteLine(ex.Message); } // create panel interface if (firstTime) { try { if (_app.UserInterfaceManager.InterfaceStyle == InterfaceStyleEnum.kRibbonInterface) { #region RIBBON AND PANELS // getting ribbons Ribbon startedRib = _app.UserInterfaceManager.Ribbons["ZeroDoc"]; //Ribbon partRib = _app.UserInterfaceManager.Ribbons["Part"]; //Ribbon assemblyRib = _app.UserInterfaceManager.Ribbons["Assembly"]; //Ribbon drawingRib = _app.UserInterfaceManager.Ribbons["Drawing"]; // getting tab RibbonTab startedTab = startedRib.RibbonTabs["id_GetStarted"]; //RibbonTab partTab = partRib.RibbonTabs["id_AddInsTab"]; //RibbonTab assemblyTab = assemblyRib.RibbonTabs["id_AddInsTab"]; //RibbonTab drawingTab = drawingRib.RibbonTabs["id_AddInsTab"]; _startedPanel = startedTab.RibbonPanels.Add(_panelDisplayName, "flecheria:TemplateAdskInventor:AOEPanelStart", _addInGuid, "", false); //_partPanel = partTab.RibbonPanels.Add(_panelDisplayName, // "flecheria:TemplateAdskInventor:AOEPanelPart", _addInGuid, "", false); //_assemblyPanel = assemblyTab.RibbonPanels.Add(_panelDisplayName, // "flecheria:TemplateAdskInventor:AOEPanelAssembly", _addInGuid, "", false); //_drawingPanel = drawingTab.RibbonPanels.Add(_panelDisplayName, // "flecheria:TemplateAdskInventor:AOEPanelDrawing", addInGuid, "", false); #endregion #region CREATE BUTTON ON STARTED TAB CommandControl startExportControl = _startedPanel.CommandControls.AddButton( _exportBtnDef, false, true, "", true); #endregion } } catch (Exception ex) { MessageBox.Show(ex.Message, "TemplateAdskInventor Error"); Debug.Write(ex.Message); } } #endregion } }
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime) { try { //the Activate 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; Button.InventorApplication = m_inventorApplication; //initialize event delegates m_userInterfaceEvents = m_inventorApplication.UserInterfaceManager.UserInterfaceEvents; UserInterfaceEventsSink_OnResetCommandBarsEventDelegate = new UserInterfaceEventsSink_OnResetCommandBarsEventHandler(UserInterfaceEvents_OnResetCommandBars); m_userInterfaceEvents.OnResetCommandBars += UserInterfaceEventsSink_OnResetCommandBarsEventDelegate; UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate = new UserInterfaceEventsSink_OnResetEnvironmentsEventHandler(UserInterfaceEvents_OnResetEnvironments); m_userInterfaceEvents.OnResetEnvironments += UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate; UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate = new UserInterfaceEventsSink_OnResetRibbonInterfaceEventHandler(UserInterfaceEvents_OnResetRibbonInterface); m_userInterfaceEvents.OnResetRibbonInterface += UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate; //load image icons for UI items //PROBLEM: i CAN NOT ADD ANOTHER ICON EXCEPT FOR SYSTEM... HOW TO DO THIS? // Icon anisotropyIcon = new Icon(this.GetType(), "\\AddSlotOption.ico"); Icon addSlotOptionIcon = new Icon(SystemIcons.Exclamation, 32, 32); //retrieve the GUID for this class GuidAttribute addInCLSID; addInCLSID = (GuidAttribute)GuidAttribute.GetCustomAttribute(typeof(StandardAddInServer), typeof(GuidAttribute)); string addInCLSIDString; addInCLSIDString = "{" + addInCLSID.Value + "}"; //create button m_addSlotOptionButton = new AddSlotOptionButton( "Add pattern", "Autodesk:Mugen:AddAnisotropyOptionCmdBtn", CommandTypesEnum.kShapeEditCmdType, addInCLSIDString, "Creates an anisotropic pattern on a given surface", "Add Anisotropic Pattern", addSlotOptionIcon, addSlotOptionIcon, ButtonDisplayEnum.kDisplayTextInLearningMode); //create the command category CommandCategory slotCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("Anisotropy", "Autodesk:Mugen:AnisotropyCmdCat", addInCLSIDString); slotCmdCategory.Add(m_addSlotOptionButton.ButtonDefinition); if (firstTime == true) { //access user interface manager UserInterfaceManager userInterfaceManager; userInterfaceManager = m_inventorApplication.UserInterfaceManager; InterfaceStyleEnum interfaceStyle; interfaceStyle = userInterfaceManager.InterfaceStyle; //create the UI for classic interface if (interfaceStyle == InterfaceStyleEnum.kClassicInterface) { //create toolbar CommandBar slotCommandBar; slotCommandBar = userInterfaceManager.CommandBars.Add("Anisotropy", "Autodesk:Mugen:AnistropyToolbar", CommandBarTypeEnum.kRegularCommandBar, addInCLSIDString); //add buttons to toolbar slotCommandBar.Controls.AddButton(m_addSlotOptionButton.ButtonDefinition, 0); //Get the 2d sketch environment base object Inventor.Environment partSketchEnvironment; partSketchEnvironment = userInterfaceManager.Environments["PMxPartEnvironment"]; //make this command bar accessible in the panel menu for the 2d sketch environment. partSketchEnvironment.PanelBar.CommandBarList.Add(slotCommandBar); } //create the UI for ribbon interface else { //get the ribbon associated with part document Inventor.Ribbons ribbons; ribbons = userInterfaceManager.Ribbons; Inventor.Ribbon partRibbon; partRibbon = ribbons["Part"]; //get the tabls associated with part ribbon RibbonTabs ribbonTabs; ribbonTabs = partRibbon.RibbonTabs; RibbonTab partSketchRibbonTab; partSketchRibbonTab = ribbonTabs["id_TabTools"]; //create a new panel with the tab RibbonPanels ribbonPanels; ribbonPanels = partSketchRibbonTab.RibbonPanels; m_partSketchSlotRibbonPanel = ribbonPanels.Add("Anysotropy", "Autodesk:Mugen:AnysotropyRibbonPanel", "{cc527b4d-c28d-40fb-a46a-4978db960594}", "", false); //add controls to the slot panel CommandControls partSketchSlotRibbonPanelCtrls; partSketchSlotRibbonPanelCtrls = m_partSketchSlotRibbonPanel.CommandControls; //add the buttons to the ribbon panel CommandControl drawSlotCmdBtnCmdCtrl; drawSlotCmdBtnCmdCtrl = partSketchSlotRibbonPanelCtrls.AddButton(m_addSlotOptionButton.ButtonDefinition, false, true, "", false); } } MessageBox.Show("This is a Carnegie Mellon University :: CERLAB test of \nAnisotropic Geometric Features Pattern Generation \nfor Industrial Design on Higly Curved Surfaces \nUsing Riemannian Metric Tensor fields \n\nAuthor: Diego Andrade \n\n2014"); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime) { try { // 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. #region Initialize AddIn members and event delegate // Initialize AddIn members. m_inventorApplication = addInSiteObject.Application; //Initialize event delegates m_userInterfaceEvents = m_inventorApplication.UserInterfaceManager.UserInterfaceEvents; UserInterfaceEventsSink_OnResetCommandBarsEventDelegate = new UserInterfaceEventsSink_OnResetCommandBarsEventHandler(UserInterfaceEvents_OnResetCommandBars); m_userInterfaceEvents.OnResetCommandBars += UserInterfaceEventsSink_OnResetCommandBarsEventDelegate; UserInterfaceEventsSink_OnEnvironmentChangeEventDelegate = new UserInterfaceEventsSink_OnEnvironmentChangeEventHandler(UserInterfaceEvents_OnEnvironmentChange); m_userInterfaceEvents.OnEnvironmentChange += UserInterfaceEventsSink_OnEnvironmentChangeEventDelegate; UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate = new UserInterfaceEventsSink_OnResetRibbonInterfaceEventHandler(UserInterfaceEventsSink_OnResetRibbonInterface); m_userInterfaceEvents.OnResetRibbonInterface += UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate; #endregion // TODO: Add ApplicationAddInServer.Activate implementation. // e.g. event initialization, command creation etc. String strAddInGUID = "{" + ((GuidAttribute)System.Attribute.GetCustomAttribute(typeof(StandardAddInServer), typeof(GuidAttribute))).Value + "}"; m_strAddInGUID = strAddInGUID; #region 创建按钮. create the buttons //get all the names of the current assembly this.IconPictureInitial(); //----------------------------------------------------------------------------------- //create the instance of the "BlockGenerator" command and button m_blockFormCmd = new BlockFormCmd(); this.CreateButton( "ValveBlockDesign.resources.BlockStandard.ico", "ValveBlockDesign.resources.BlockLarge.ico", m_blockFormCmd, "块", "AppBlockGenerateCmd", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "Generate a block", "Generate a block with parameters entered by user", ButtonDisplayEnum.kDisplayTextInLearningMode, false); //----------------------------------------------------------------------------------- //create the instance of the "Align" command and button m_alignCmd = new AlignCmd(); this.CreateButton( "ValveBlockDesign.resources.AlignStandard.ico", "ValveBlockDesign.resources.AlignLarge.ico", m_alignCmd, "对齐", "AppAlignCmd", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "Cavity align", "Cavity align", ButtonDisplayEnum.kDisplayTextInLearningMode, false); //----------------------------------------------------------------------------------- //create the instance of the "ExtractiFeature" command and button m_extractiFeatureCmd = new ExtractiFeatureCmd(); this.CreateButton( "ValveBlockDesign.resources.ExtractiFeatureStandard.ico", "ValveBlockDesign.resources.ExtractiFeatureLarge.ico", m_extractiFeatureCmd, "提取模型", "AppExtractiFeatureCmd", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "提取特征", "提取特征", ButtonDisplayEnum.kDisplayTextInLearningMode, false); //----------------------------------------------------------------------------------- //create the instance of the "InsertiFeature" command and button m_iFeatureFormCmd = new iFeatureFormCmd(); this.CreateButton( "ValveBlockDesign.resources.InsertiFeatureStandard.ico", "ValveBlockDesign.resources.InsertiFeatureLarge.ico", m_iFeatureFormCmd, "元件特征", "AppInsertiFeatureCmd", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "插入特征", "插入特征", ButtonDisplayEnum.kDisplayTextInLearningMode, false); //----------------------------------------------------------------------------------- //create the instance of the "DeleteiFeature" command and button m_deleteCmd = new DeleteCmd(); this.CreateButton( "ValveBlockDesign.resources.DeleteCmdStandard.ico", "ValveBlockDesign.resources.DeleteCmdLarge.ico", m_deleteCmd, "删除", "AppDeleteiFeatureCmd", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "删除特征", "删除特征", ButtonDisplayEnum.kDisplayTextInLearningMode, false); //----------------------------------------------------------------------------------- //create the instance of the "RotateiFeature" command and button m_rotateCmd = new RotateCmd(); this.CreateButton( "ValveBlockDesign.resources.RotateCmdStandard.ico", "ValveBlockDesign.resources.RotateCmdLarge.ico", m_rotateCmd, "旋转", "AppRotateiFeatureCmd", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "旋转特征", "旋转特征", ButtonDisplayEnum.kDisplayTextInLearningMode, false); //----------------------------------------------------------------------------------- //create the instance of the "InsertOutline" command and button m_insertOutlineCmd = new InsertOutlineCmd(); this.CreateButton( "ValveBlockDesign.resources.InsertiFeatureStandard.ico", "ValveBlockDesign.resources.OutLineCmdLarge.ico", m_insertOutlineCmd, "安装外形", "AppInsertOutlineCmd", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "插入安装外形", "插入安装外形", ButtonDisplayEnum.kDisplayTextInLearningMode, false); //----------------------------------------------------------------------------------- //create the instance of the "Move" command and button m_moveCmd = new MoveCmd(); this.CreateButton( "ValveBlockDesign.resources.MoveCmdStandard.ico", "ValveBlockDesign.resources.MoveCmdLarge.ico", m_moveCmd, "移动", "AppMoveCmd", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "移动孔", "移动孔", ButtonDisplayEnum.kDisplayTextInLearningMode, false); //----------------------------------------------------------------------------------- //create the instance of the "Connect" command and button m_connectCmd = new ConnectCmd(); this.CreateButton( "ValveBlockDesign.resources.ConnectStandard.ico", "ValveBlockDesign.resources.ConnectLarge.ico", m_connectCmd, "连接", "AppConnectCmd", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "连接孔", "连接孔", ButtonDisplayEnum.kDisplayTextInLearningMode, false); //----------------------------------------------------------------------------------- //create the instance of the "Edit" command and button m_cavityLibraryEditCmd = new CavityLibraryEditCmd(); this.CreateButton( "ValveBlockDesign.resources.EditCavityCmdStandard.ico", "ValveBlockDesign.resources.EditCavityCmdLarge.ico", m_cavityLibraryEditCmd, "修改元件", "AppEditLibraryCmd", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "修改元件参数", "修改元件参数", ButtonDisplayEnum.kDisplayTextInLearningMode, false); //----------------------------------------------------------------------------------- //create the instance of the "Add" command and button m_cavityLibraryAddCmd = new CavityLibraryAddCmd(); this.CreateButton( "ValveBlockDesign.resources.AddCavityCmdStandard.ico", "ValveBlockDesign.resources.AddCavityCmdLarge.ico", m_cavityLibraryAddCmd, "添加元件", "AppAddLibraryCmd", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "添加新元件", "添加新元件", ButtonDisplayEnum.kDisplayTextInLearningMode, false); //----------------------------------------------------------------------------------- m_cavityLibraryScanCmd = new CavityLibraryScanCmd(); this.CreateButton( "ValveBlockDesign.resources.ScanCavityCmdStandard.ico", "ValveBlockDesign.resources.ScanCavityCmdLarge.ico", m_cavityLibraryScanCmd, "浏览元件", "AppScanLibraryCmd", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "浏览库中元件", "浏览库中元件", ButtonDisplayEnum.kDisplayTextInLearningMode, false); //----------------------------------------------------------------------------------- m_boltHolesFormCmd = new BoltHolesFormCmd(); this.CreateButton( "ValveBlockDesign.resources.BoltHolesCmdStandard.ico", "ValveBlockDesign.resources.BoltHolesCmdLarge.ico", m_boltHolesFormCmd, "安装螺纹孔", "AppInsertBoltHolesCmd", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "插入安装螺纹孔", "插入安装螺纹孔", ButtonDisplayEnum.kDisplayTextInLearningMode, false); //--------------------------------------------------------------------------------- m_insertXportCmd = new InsertXportCmd(); this.CreateButton( "ValveBlockDesign.resources.BoltHolesCmdStandard.ico", "ValveBlockDesign.resources.Xport.ico", m_insertXportCmd, "工艺孔", "AppInsertXportCmd", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "插入工艺孔", "插入工艺孔", ButtonDisplayEnum.kDisplayTextInLearningMode, false); //--------------------------------------------------------------------------------- m_editNetCmd = new EditNetCmd(); this.CreateButton( "ValveBlockDesign.resources.BoltHolesCmdStandard.ico", "ValveBlockDesign.resources.EditColor.ico", m_editNetCmd, "修改网络", "AppEditNetCmd", CommandTypesEnum.kShapeEditCmdType, strAddInGUID, "修改油孔网络", "修改油孔网络", ButtonDisplayEnum.kDisplayTextInLearningMode, false); //--------------------------------------------------------------------------------- #endregion #region 设置ChangeManager和CommandCategory. Set the ChangeManager and CommandCategory //Create change definitions //get the change manager ChangeManager oChangeManager = m_inventorApplication.ChangeManager; //Create the change definition collections ChangeDefinitions oChangeDefs = oChangeManager.Add(strAddInGUID); //----------------------------------------------------------------------------------- //Create the "Block" change definition ChangeDefinition oBlockChangeDef = oChangeDefs.Add("AppBlockGenerateChgDef", "块"); //Create the command category CommandCategory oBlockCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("块", "AppBlockGenerateCmdCat", strAddInGUID); oBlockCmdCategory.Add(m_blockFormCmd.ButtonDefinition); //----------------------------------------------------------------------------------- ChangeDefinition oAlignChangeDef = oChangeDefs.Add("AppAlignChgDef", "对齐"); CommandCategory oAlignCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("对齐", "AppAlignCmdCat", strAddInGUID); oAlignCmdCategory.Add(m_alignCmd.ButtonDefinition); //----------------------------------------------------------------------------------- ChangeDefinition oExtractiFeatureChangeDef = oChangeDefs.Add("AppExtractiFeatureChgDef", "提取特征"); CommandCategory oExtractiFeatureCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("提取特征", "AppExtractiFeatureCmdCat", strAddInGUID); oExtractiFeatureCmdCategory.Add(m_extractiFeatureCmd.ButtonDefinition); //----------------------------------------------------------------------------------- ChangeDefinition oInsertiFeatureChangeDef = oChangeDefs.Add("AppInsertiFeatureChgDef", "插入特征"); CommandCategory oInsertiFeatureCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("插入特征", "AppInsertiFeatureCmdCat", strAddInGUID); oInsertiFeatureCmdCategory.Add(m_iFeatureFormCmd.ButtonDefinition); //----------------------------------------------------------------------------------- ChangeDefinition oDeleteiFeatureChangeDef = oChangeDefs.Add("AppDeleteiFeatureChgDef", "删除特征"); CommandCategory oDeleteiFeatureCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("删除特征", "AppDeleteiFeatureCmdCat", strAddInGUID); oDeleteiFeatureCmdCategory.Add(m_deleteCmd.ButtonDefinition); //----------------------------------------------------------------------------------- ChangeDefinition oRotateiFeatureChangeDef = oChangeDefs.Add("AppRotateiFeatureChgDef", "旋转特征"); CommandCategory oRotateiFeatureCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("旋转特征", "AppRotateiFeatureCmdCat", strAddInGUID); oRotateiFeatureCmdCategory.Add(m_rotateCmd.ButtonDefinition); //----------------------------------------------------------------------------------- ChangeDefinition oMoveChangeDef = oChangeDefs.Add("AppMoveChgDef", "移动孔"); CommandCategory oMoveCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("移动孔", "AppMoveCmdCat", strAddInGUID); oMoveCmdCategory.Add(m_moveCmd.ButtonDefinition); //----------------------------------------------------------------------------------- ChangeDefinition oInsertOutlineChangeDef = oChangeDefs.Add("AppInsertOutlineChgDef", "插入安装外形"); CommandCategory oInsertOutlineCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("插入安装外形", "AppInsertOutlineCmdCat", strAddInGUID); oInsertOutlineCmdCategory.Add(m_insertOutlineCmd.ButtonDefinition); //----------------------------------------------------------------------------------- ChangeDefinition oInsertXportChangeDef = oChangeDefs.Add("AppInsertXportChgDef", "插入工艺孔"); CommandCategory oInsertXportCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("插入工艺孔", "AppInsertXportCmdCat", strAddInGUID); oInsertXportCmdCategory.Add(m_insertXportCmd.ButtonDefinition); //----------------------------------------------------------------------------------- ChangeDefinition oEditNetChangeDef = oChangeDefs.Add("AppEditNetChgDef", "修改油孔网络"); CommandCategory oEitNetCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("修改油孔网络", "AppEditNetCmdCat", strAddInGUID); oEitNetCmdCategory.Add(m_editNetCmd.ButtonDefinition); //----------------------------------------------------------------------------------- ChangeDefinition oConnectDef = oChangeDefs.Add("AppConnectChgDef", "连接"); CommandCategory oConnectCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("连接", "AppConnectCmdCat", strAddInGUID); oConnectCmdCategory.Add(m_connectCmd.ButtonDefinition); //----------------------------------------------------------------------------------- ChangeDefinition oEditLibraryDef = oChangeDefs.Add("AppEditLibraryChgDef", "修改参数"); CommandCategory oEditLibraryCategory = m_inventorApplication.CommandManager.CommandCategories.Add("修改参数", "AppEditLibraryCmdCat", strAddInGUID); oEditLibraryCategory.Add(m_cavityLibraryEditCmd.ButtonDefinition); //----------------------------------------------------------------------------------- ChangeDefinition oAddLibraryDef = oChangeDefs.Add("AppAddLibraryChgDef", "添加特征元件"); CommandCategory oAddLibraryCategory = m_inventorApplication.CommandManager.CommandCategories.Add("添加特征元件", "AppAddLibraryCmdCat", strAddInGUID); oAddLibraryCategory.Add(m_cavityLibraryAddCmd.ButtonDefinition); //----------------------------------------------------------------------------------- ChangeDefinition oScanLibraryDef = oChangeDefs.Add("AppScanLibraryChgDef", "浏览特征元件"); CommandCategory oScanLibraryCategory = m_inventorApplication.CommandManager.CommandCategories.Add("浏览特征元件", "AppScanLibraryCmdCat", strAddInGUID); oScanLibraryCategory.Add(m_cavityLibraryScanCmd.ButtonDefinition); //----------------------------------------------------------------------------------- ChangeDefinition oInsertBoltHolesDef = oChangeDefs.Add("AppInsertBoltHolesChgDef", "插入安装螺纹孔"); CommandCategory oInsertBoltHolesCategory = m_inventorApplication.CommandManager.CommandCategories.Add("插入安装螺纹孔", "AppInsertBoltHolesCmdCat", strAddInGUID); oInsertBoltHolesCategory.Add(m_boltHolesFormCmd.ButtonDefinition); //----------------------------------------------------------------------------------- #endregion #region 加载Ribbon面板. Load the Ribbon Panel. if (firstTime) { Ribbon partDocRibbon; partDocRibbon = m_inventorApplication.UserInterfaceManager.Ribbons["Part"]; RibbonTab myRibbonTab; myRibbonTab = partDocRibbon.RibbonTabs.Add( "阀块设计", "id_TabBlockDesign", strAddInGUID, "", false); RibbonPanels ribbonPanels; ribbonPanels = myRibbonTab.RibbonPanels; RibbonPanel cubePanel; cubePanel = ribbonPanels.Add( "块", "id_Panel_Block", strAddInGUID, "", false); CommandControls blockPanelCtrls; blockPanelCtrls = cubePanel.CommandControls; CommandControl cubePanelCtrl; cubePanelCtrl = blockPanelCtrls.AddButton( m_blockFormCmd.ButtonDefinition, true, true, "", false); //------------------------------------------------------------------ //---------------------------------------------- //对iFeature特征操作 RibbonPanel iFeaturePanel; iFeaturePanel = ribbonPanels.Add( "插入", "id_Panel_iFeature", strAddInGUID, "", false); CommandControls iFeatureCtrls; iFeatureCtrls = iFeaturePanel.CommandControls; CommandControl InsertiFeatureCtrl;//插入元件 InsertiFeatureCtrl = iFeatureCtrls.AddButton( m_iFeatureFormCmd.ButtonDefinition, true, true, "", false); CommandControl InsertOutlineCtrl;//插入安装外形 InsertOutlineCtrl = iFeatureCtrls.AddButton( m_insertOutlineCmd.ButtonDefinition, true, true, "", true); CommandControl InsertBoltHolesCtrl;//安装螺纹孔 InsertBoltHolesCtrl = iFeatureCtrls.AddButton( m_boltHolesFormCmd.ButtonDefinition, true, true, "", false); //------------------------------------------------------------------------------- //RibbonPanel connectPanel; //connectPanel = ribbonPanels.Add( // "连接", // "id_Panel_Connect", // strAddInGUID, // "", // false); //CommandControls connectCtrls; //connectCtrls = connectPanel.CommandControls; RibbonPanel modifyPanel; modifyPanel = ribbonPanels.Add( "修改", "id_Panel_Edit", strAddInGUID, "", false); CommandControls modifyCtrls; modifyCtrls = modifyPanel.CommandControls; CommandControl AlignCtrl; AlignCtrl = modifyCtrls.AddButton( m_alignCmd.ButtonDefinition, true, true, "", false); CommandControl MoveCtrl; MoveCtrl = modifyCtrls.AddButton( m_moveCmd.ButtonDefinition, true, true, "", false); CommandControl DeleteCtrl;//删除元件特征 DeleteCtrl = modifyCtrls.AddButton( m_deleteCmd.ButtonDefinition, true, true, "", false); CommandControl EditPortCtrl;//修改网络 EditPortCtrl = modifyCtrls.AddButton( m_editNetCmd.ButtonDefinition, true, true, "", true); CommandControl RotateCtrl;//旋转元件特征 RotateCtrl = modifyCtrls.AddButton( m_rotateCmd.ButtonDefinition, true, true, "", false); //-------------------------------------------------------- RibbonPanel ConnectPanel; ConnectPanel = ribbonPanels.Add( "连通油路", "id_Panel_Connection", strAddInGUID, "", false); CommandControls ConnectCtrls; ConnectCtrls = ConnectPanel.CommandControls; CommandControl ConnectCtrl; ConnectCtrl = ConnectCtrls.AddButton( m_connectCmd.ButtonDefinition, true, true, "", false); CommandControl InsertXportCtrl;//插入工艺孔 InsertXportCtrl = ConnectCtrls.AddButton( m_insertXportCmd.ButtonDefinition, true, true, "", true); //------------------------------------------------------------ //元件库的操作面板 RibbonPanel CavityLibraryPanel; CavityLibraryPanel = ribbonPanels.Add( "元件库", "id_Panel_CavityLibrary", strAddInGUID, "", false); CommandControls CavityLibraryCtrls; CavityLibraryCtrls = CavityLibraryPanel.CommandControls; CommandControl EditCavityCtrl; EditCavityCtrl = CavityLibraryCtrls.AddButton( m_cavityLibraryEditCmd.ButtonDefinition, true, true, "", false); CommandControl AddCavityCtrl; AddCavityCtrl = CavityLibraryCtrls.AddButton( m_cavityLibraryAddCmd.ButtonDefinition, true, true, "", false); CommandControl ScanCavityCtrl; ScanCavityCtrl = CavityLibraryCtrls.AddButton( m_cavityLibraryScanCmd.ButtonDefinition, true, true, "", false); CommandControl ExtractiFeatureCtrl; ExtractiFeatureCtrl = CavityLibraryCtrls.AddButton( m_extractiFeatureCmd.ButtonDefinition, true, true, "", false); } #endregion } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); } }
//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"); }
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. ControlDefinitions oCtrlDefs = m_inventorApplication.CommandManager.ControlDefinitions; System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); string[] resources = assembly.GetManifestResourceNames(); System.IO.Stream oStream32 = assembly.GetManifestResourceStream("RibbonDemoAddin.resources.button 32x32.ico"); System.IO.Stream oStream16 = assembly.GetManifestResourceStream("RibbonDemoAddin.resources.button 16x16.ico"); System.Drawing.Icon oIcon32 = new System.Drawing.Icon(oStream32); System.Drawing.Icon oIcon16 = new System.Drawing.Icon(oStream16); object oIPictureDisp32 = AxHostConverter.ImageToPictureDisp(oIcon32.ToBitmap()); object oIPictureDisp16 = AxHostConverter.ImageToPictureDisp(oIcon16.ToBitmap()); try { _buttonDef1 = oCtrlDefs["Autodesk:BrowserDemo:ButtonDef1"] as ButtonDefinition; } catch (Exception ex) { _buttonDef1 = oCtrlDefs.AddButtonDefinition("Ribbon Demo1", "Autodesk:RibbonDemoC#:ButtonDef1", CommandTypesEnum.kEditMaskCmdType, addInGuid, "Ribbon Demo", "Ribbon Demo Description", oIPictureDisp16, oIPictureDisp32, ButtonDisplayEnum.kDisplayTextInLearningMode); CommandCategory cmdCat = m_inventorApplication.CommandManager.CommandCategories.Add("RibbonDemo C#", "Autodesk:CmdCategory:RibbonDemoC#", addInGuid); cmdCat.Add(_buttonDef1); } if (firstTime) { try { if (m_inventorApplication.UserInterfaceManager.InterfaceStyle == InterfaceStyleEnum.kRibbonInterface) { Ribbon ribbon = m_inventorApplication.UserInterfaceManager.Ribbons["Part"]; RibbonTab tab = ribbon.RibbonTabs["id_TabModel"]; try { RibbonPanel panel = tab.RibbonPanels.Add("Ribbon Demo", "Autodesk:RibbonDemoC#:Panel1", addInGuid, "", false); CommandControl control1 = panel.CommandControls.AddButton(_buttonDef1, true, true, "", false); } catch (Exception ex) { } } else { CommandBar oCommandBar = m_inventorApplication.UserInterfaceManager.CommandBars["PMxPartFeatureCmdBar"]; oCommandBar.Controls.AddButton(_buttonDef1, 0); } } catch { CommandBar oCommandBar = m_inventorApplication.UserInterfaceManager.CommandBars["PMxPartFeatureCmdBar"]; oCommandBar.Controls.AddButton(_buttonDef1, 0); } } _buttonDef1.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(_buttonDef1_OnExecute); }