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) { 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 { 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) { 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()); } }
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 m_userInterfaceEvents.OnResetCommandBars -= UserInterfaceEventsSink_OnResetCommandBarsEventDelegate; m_userInterfaceEvents.OnEnvironmentChange -= UserInterfaceEventsSink_OnEnvironmentChangeEventDelegate; m_userInterfaceEvents.OnResetRibbonInterface -= UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate; UserInterfaceEventsSink_OnResetCommandBarsEventDelegate = null; UserInterfaceEventsSink_OnEnvironmentChangeEventDelegate = null; UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate = null; m_userInterfaceEvents = null; //remove the command button(s) m_blockFormCmd.RemoveButton(); m_alignCmd.RemoveButton(); m_extractiFeatureCmd.RemoveButton(); m_iFeatureFormCmd.RemoveButton(); m_moveCmd.RemoveButton(); m_connectCmd.RemoveButton(); m_cavityLibraryEditCmd.RemoveButton(); m_cavityLibraryScanCmd.RemoveButton(); m_cavityLibraryAddCmd.RemoveButton(); m_boltHolesFormCmd.RemoveButton(); m_deleteCmd.RemoveButton(); m_rotateCmd.RemoveButton(); m_insertOutlineCmd.RemoveButton(); m_insertXportCmd.RemoveButton(); m_editNetCmd.RemoveButton(); m_blockFormCmd = null; m_alignCmd = null; m_extractiFeatureCmd = null; m_iFeatureFormCmd = null; m_moveCmd = null; m_connectCmd = null; m_cavityLibraryEditCmd = null; m_cavityLibraryAddCmd = null; m_cavityLibraryScanCmd = null; m_boltHolesFormCmd = null; m_deleteCmd = null; m_rotateCmd = null; m_insertOutlineCmd = null; m_insertXportCmd = null; m_editNetCmd = null; //----------------------------------------------------------------------------------- //delete change definitions ChangeManager oChangeManager = m_inventorApplication.ChangeManager; ChangeDefinitions oChangeDefinition = oChangeManager[m_strAddInGUID]; //----------------------------------------------------------------------------------- ChangeDefinition oBlockFormChangeDefinition = oChangeDefinition["AppBlockGenerateChgDef"]; oBlockFormChangeDefinition.Delete(); //----------------------------------------------------------------------------------- ChangeDefinition oAlignChangeDefinition = oChangeDefinition["AppAlignChgDef"]; oAlignChangeDefinition.Delete(); //----------------------------------------------------------------------------------- ChangeDefinition oExtractChangeDefinition = oChangeDefinition["AppExtractiFeatureChgDef"]; oExtractChangeDefinition.Delete(); //----------------------------------------------------------------------------------- ChangeDefinition oInsertChangeDefinition = oChangeDefinition["AppInsertiFeatureChgDef"]; oInsertChangeDefinition.Delete(); //----------------------------------------------------------------------------------- ChangeDefinition oDeleteChangeDefinition = oChangeDefinition["AppDeleteiFeatureChgDef"]; oDeleteChangeDefinition.Delete(); //----------------------------------------------------------------------------------- ChangeDefinition oRotateChangeDefinition = oChangeDefinition["AppRotateiFeatureChgDef"]; oRotateChangeDefinition.Delete(); //----------------------------------------------------------------------------------- ChangeDefinition oInsertOutlineChangeDefinition = oChangeDefinition["AppInsertOutlineChgDef"]; oInsertOutlineChangeDefinition.Delete(); //----------------------------------------------------------------------------------- ChangeDefinition oMoveDefinition = oChangeDefinition["AppMoveChgDef"]; oMoveDefinition.Delete(); //----------------------------------------------------------------------------------- ChangeDefinition oInsertXportDefinition = oChangeDefinition["AppInsertXportChgDef"]; oInsertXportDefinition.Delete(); //----------------------------------------------------------------------------------- ChangeDefinition oEditNetDefinition = oChangeDefinition["AppEditNetChgDef"]; oEditNetDefinition.Delete(); //----------------------------------------------------------------------------------- ChangeDefinition oConnectDefinition = oChangeDefinition["AppConnectChgDef"]; oConnectDefinition.Delete(); //----------------------------------------------------------------------------------- ChangeDefinition oEditLibraryDefinition = oChangeDefinition["AppEditLibraryChgDef"]; oEditLibraryDefinition.Delete(); //----------------------------------------------------------------------------------- ChangeDefinition oAddLibraryDefinition = oChangeDefinition["AppAddLibraryChgDef"]; oAddLibraryDefinition.Delete(); //----------------------------------------------------------------------------------- ChangeDefinition oScanLibraryDefinition = oChangeDefinition["AppScanLibraryChgDef"]; oScanLibraryDefinition.Delete(); //----------------------------------------------------------------------------------- ChangeDefinition oInsertBoltHolesDefinition = oChangeDefinition["AppInsertBoltHolesChgDef"]; oInsertBoltHolesDefinition.Delete(); //----------------------------------------------------------------------------------- // Release objects. //释放对象 Marshal.ReleaseComObject(m_inventorApplication); m_inventorApplication = null; GC.Collect(); GC.WaitForPendingFinalizers(); }