/// <summary> /// Checks to make sure that you are in an assembly document and then readies for environment changing /// </summary> /// <param name="Environment"></param> /// <param name="EnvironmentState"></param> /// <param name="BeforeOrAfter"></param> /// <param name="Context"></param> /// <param name="HandlingCode"></param> private void UIEvents_OnEnvironmentChange(Inventor.Environment Environment, EnvironmentStateEnum EnvironmentState, EventTimingEnum BeforeOrAfter, NameValueMap Context, out HandlingCodeEnum HandlingCode) { if (Environment.Equals(ExporterEnv) && BeforeOrAfter == EventTimingEnum.kBefore) { if (EnvironmentState == EnvironmentStateEnum.kActivateEnvironmentState) { // User may not open documents other than assemblies if (!(Context.Item["Document"] is AssemblyDocument assembly)) { MessageBox.Show("Only assemblies can be used with the robot exporter.", "Invalid Document", MessageBoxButtons.OK); exporterBlocked = true; // Quit the exporter if (Context.Item["Document"] is DrawingDocument drawing) { ForceQuitExporter(drawing); } else if (Context.Item["Document"] is PartDocument part) { ForceQuitExporter(part); } else if (Context.Item["Document"] is PresentationDocument presentation) { ForceQuitExporter(presentation); } } // User may not open multiple documents in the exporter else if (EnvironmentEnabled) { MessageBox.Show("The exporter may only be used in one assembly at a time. " + "Please finish using the exporter in \"" + AsmDocument.DisplayName + "\" to continue.", "Too Many Assemblies", MessageBoxButtons.OK); exporterBlocked = true; ForceQuitExporter(assembly); } else { OpeningExporter(); } } else if (EnvironmentState == EnvironmentStateEnum.kTerminateEnvironmentState && EnvironmentEnabled) { if (exporterBlocked) { exporterBlocked = false; } else { ClosingExporter(); } } }
protected override void ButtonDefinition_OnExecute(NameValueMap context) { Inventor.Environment currEnvironment = m_inventorApplication.UserInterfaceManager.ActiveEnvironment; if (currEnvironment.InternalName != "PMxPartEnvironment") { System.Windows.Forms.MessageBox.Show("该命令必须在零件环境中运行!"); return; } //if command was already started, stop it first if (m_commandIsRunning) { StopCommand(); } //start new command StartCommand(); }
public void UnloadPlugin() { try { OnFinishClick(); mRibbon.UnloadRibbon(); if (mInventorApp.ActiveEnvironment.DisplayName == Resources.IDC_TAB_DISPLAY_NAME) { if (mInventorApp.ActiveDocument.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject) { AssemblyDocument asmDoc = (AssemblyDocument)mInventorApp.ActiveDocument; Inventor.Environment asmEnv = asmDoc.EnvironmentManager.BaseEnvironment; asmDoc.EnvironmentManager.SetCurrentEnvironment(asmEnv); } if (mInventorApp.ActiveDocument.DocumentType == DocumentTypeEnum.kPartDocumentObject) { PartDocument partDoc = (PartDocument)mInventorApp.ActiveDocument; Inventor.Environment partEnv = partDoc.EnvironmentManager.BaseEnvironment; partDoc.EnvironmentManager.SetCurrentEnvironment(partEnv); } if (mInventorApp.ActiveDocument.DocumentType == DocumentTypeEnum.kDrawingDocumentObject) { DrawingDocument drwDoc = (DrawingDocument)mInventorApp.ActiveDocument; Inventor.Environment drwEnv = drwDoc.EnvironmentManager.BaseEnvironment; drwDoc.EnvironmentManager.SetCurrentEnvironment(drwEnv); } } if (null != mRibbon.mRubiksPartTab) { mRibbon.mRubiksPartTab.Delete(); mRibbon.mRubiksPartTab = null; } if (null != mRibbon.mEnvironment) { mRibbon.mEnvironment.Delete(); mRibbon.mEnvironment = null; } } catch (Exception ex) { MessageBox.Show(ex.InnerException.StackTrace); } }
private int FindEnvironment(Inventor.Environment env, ControlDefinition ctrlDef) { try { int index = 0; for (int i = 1; i <= env.DisabledCommandList.Count; i++) { if (ctrlDef == env.DisabledCommandList[i]) { index = i; break; } } return(index); } catch (Exception e) { } return(0); }
protected override void DestroyEnvironment() { exporterEnv.Delete(); exporterEnv = null; }
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. try { // Initialize AddIn members. m_inventorApplication = addInSiteObject.Application; Button.InventorApplication = m_inventorApplication; //retrieve the GUID for this class var addInClsidString = GetGUIDForThisClass(); //create icons from files var ordToChainIcon = new Icon(GetType(), "btn-ord-to-chain.ico"); var chainToOrdIcon = new Icon(GetType(), "btn-chain-to-ord.ico"); //create buttons var identifierPrefix = "Autodesk:ChangeDimensionSets:"; m_convertOrdinateToChain = new OrdToChainButton( "Ordinate To Chain", identifierPrefix + "OrdToChainButton", CommandTypesEnum.kShapeEditCmdType, addInClsidString, "Ordinate To Chain", "Convert Ordinate To Chain Dimension", ordToChainIcon, ordToChainIcon, ButtonDisplayEnum.kDisplayTextInLearningMode); m_convertChainToOrdinate = new ChainToOrdButton( "Chain To Ordinate", identifierPrefix + "ChainToOrdButton", CommandTypesEnum.kShapeEditCmdType, addInClsidString, "Chain To Ordinate", "Convert Chain To Ordinate Dimension", chainToOrdIcon, chainToOrdIcon, ButtonDisplayEnum.kDisplayTextInLearningMode); //create command category var catName = "Dimensions"; var commandCategory = m_inventorApplication.CommandManager.CommandCategories.Add(catName, identifierPrefix + "ChangeDimensionSetsCategory", addInClsidString); commandCategory.Add(m_convertOrdinateToChain.ButtonDefinition); commandCategory.Add(m_convertChainToOrdinate.ButtonDefinition); if (firstTime == true) { //access user interface manager var userInterfaceManager = m_inventorApplication.UserInterfaceManager; var interfaceStyle = userInterfaceManager.InterfaceStyle; //create the UI for classic interface if (interfaceStyle == InterfaceStyleEnum.kClassicInterface) { // Create command bar var commandBar = userInterfaceManager.CommandBars.Add(catName, identifierPrefix + "ChangeDimensionSetsToolbar", CommandBarTypeEnum.kRegularCommandBar, addInClsidString); //add buttons to toolbar commandBar.Controls.AddButton(m_convertOrdinateToChain.ButtonDefinition); commandBar.Controls.AddButton(m_convertChainToOrdinate.ButtonDefinition); //Get the 2d sketch environment base object Inventor.Environment partSketchEnvironment = userInterfaceManager.Environments["DLxDrawingEnvironment"]; //make this command bar accessible in the panel menu for the 2d sketch environment. partSketchEnvironment.PanelBar.CommandBarList.Add(commandBar); } else { //get the ribbon associated with part document var ribbons = userInterfaceManager.Ribbons; var partRibbon = ribbons["Drawing"]; //get the tabls associated with part ribbon var ribbonTabs = partRibbon.RibbonTabs; var partSketchRibbonTab = ribbonTabs["id_TabAnnotate"]; //create a new panel with the tab var ribbonPanels = partSketchRibbonTab.RibbonPanels; m_DimensionSwitch_ribbonPanel = ribbonPanels.Add(catName, identifierPrefix + "SlotRibbonPanel", addInClsidString); //add controls to the slot panel var partSketchSlotRibbonPanelCtrls = m_DimensionSwitch_ribbonPanel.CommandControls; //add the buttons to the ribbon panel partSketchSlotRibbonPanelCtrls.AddButton(m_convertOrdinateToChain.ButtonDefinition); partSketchSlotRibbonPanelCtrls.AddButton(m_convertChainToOrdinate.ButtonDefinition); } } } catch (Exception e) { MessageBox.Show(e.Message.ToString()); MessageBox.Show(e.StackTrace.ToString()); } }
/// <summary> /// Called when the <see cref="StandardAddInServer"/> is being loaded /// </summary> /// <param name="AddInSiteObject"></param> /// <param name="FirstTime"></param> public void Activate(ApplicationAddInSite AddInSiteObject, bool FirstTime) { MainApplication = AddInSiteObject.Application; //Gets the application object, which is used in many different ways throughout this whole process string ClientID = "{0c9a07ad-2768-4a62-950a-b5e33b88e4a3}"; Utilities.LoadSettings(); #region Add Parallel Environment #region Load Images stdole.IPictureDisp ExportRobotIconSmall = PictureDispConverter.ToIPictureDisp(new Bitmap(Resource.SynthesisLogo16)); stdole.IPictureDisp ExportRobotIconLarge = PictureDispConverter.ToIPictureDisp(new Bitmap(Resource.SynthesisLogo32)); stdole.IPictureDisp SaveRobotIconSmall = PictureDispConverter.ToIPictureDisp(new Bitmap(Resource.Save16)); stdole.IPictureDisp SaveRobotIconLarge = PictureDispConverter.ToIPictureDisp(new Bitmap(Resource.Save32)); stdole.IPictureDisp ExportSetupRobotIconSmall = PictureDispConverter.ToIPictureDisp(new Bitmap(Resource.Gears16)); stdole.IPictureDisp ExportSetupRobotIconLarge = PictureDispConverter.ToIPictureDisp(new Bitmap(Resource.Gears32)); stdole.IPictureDisp YeetRobotIconSmall = PictureDispConverter.ToIPictureDisp(new Bitmap(Resource.Wand16));//these are still here at request of QA stdole.IPictureDisp YeetRobotIconLarge = PictureDispConverter.ToIPictureDisp(new Bitmap(Resource.Wand32)); stdole.IPictureDisp WeightRobotIconSmall = PictureDispConverter.ToIPictureDisp(new Bitmap(Resource.Weight16)); stdole.IPictureDisp WeightRobotIconLarge = PictureDispConverter.ToIPictureDisp(new Bitmap(Resource.Weight32)); stdole.IPictureDisp SynthesisLogoSmall = PictureDispConverter.ToIPictureDisp(new Bitmap(Resource.SynthesisLogo16)); stdole.IPictureDisp SynthesisLogoLarge = PictureDispConverter.ToIPictureDisp(new Bitmap(Resource.SynthesisLogo32)); #region DEBUG #if DEBUG stdole.IPictureDisp DebugButtonSmall = PictureDispConverter.ToIPictureDisp(new Bitmap(Resource.Wand16)); stdole.IPictureDisp DebugButtonLarge = PictureDispConverter.ToIPictureDisp(new Bitmap(Resource.Wand32)); #endif #endregion #endregion #region UI Creation #region Setup New Environment and Ribbon Environments environments = MainApplication.UserInterfaceManager.Environments; ExporterEnv = environments.Add("Robot Exporter", "BxD:RobotExporter:Environment", null, SynthesisLogoSmall, SynthesisLogoLarge); Ribbon assemblyRibbon = MainApplication.UserInterfaceManager.Ribbons["Assembly"]; RibbonTab ExporterTab = assemblyRibbon.RibbonTabs.Add("Robot Exporter", "BxD:RobotExporter:RobotExporterTab", ClientID, "", false, true); ControlDefinitions ControlDefs = MainApplication.CommandManager.ControlDefinitions; SetupPanel = ExporterTab.RibbonPanels.Add("Start Over", "BxD:RobotExporter:SetupPanel", ClientID); SettingsPanel = ExporterTab.RibbonPanels.Add("Settings", "BxD:RobotExporter:SettingsPanel", ClientID); FilePanel = ExporterTab.RibbonPanels.Add("File", "BxD:RobotExporter:FilePanel", ClientID); // Reset positioning of panels SettingsPanel.Reposition("BxD:RobotExporter:SetupPanel", false); FilePanel.Reposition("BxD:RobotExporter:SettingsPanel", false); #endregion #region Setup Buttons //Begin Wizard Export WizardExportButton = ControlDefs.AddButtonDefinition("Exporter Setup", "BxD:RobotExporter:BeginWizardExport", CommandTypesEnum.kNonShapeEditCmdType, ClientID, null, "Quickly configure wheel and joint information.", ExportSetupRobotIconSmall, ExportSetupRobotIconLarge); WizardExportButton.OnExecute += BeginWizardExport_OnExecute; WizardExportButton.OnHelp += _OnHelp; SetupPanel.CommandControls.AddButton(WizardExportButton, true); //Set Weight SetWeightButton = ControlDefs.AddButtonDefinition("Robot Weight", "BxD:RobotExporter:SetWeight", CommandTypesEnum.kNonShapeEditCmdType, ClientID, null, "Change the weight of the robot.", WeightRobotIconSmall, WeightRobotIconLarge); SetWeightButton.OnExecute += SetWeight_OnExecute; SetWeightButton.OnHelp += _OnHelp; SettingsPanel.CommandControls.AddButton(SetWeightButton, true); //Save Button SaveButton = ControlDefs.AddButtonDefinition("Save Configuration", "BxD:RobotExporter:SaveRobot", CommandTypesEnum.kNonShapeEditCmdType, ClientID, null, "Save robot configuration to your assembly file for future exporting.", SaveRobotIconSmall, SaveRobotIconLarge); SaveButton.OnExecute += SaveButton_OnExecute; SaveButton.OnHelp += _OnHelp; FilePanel.CommandControls.AddButton(SaveButton, true); //Export Button ExportButton = ControlDefs.AddButtonDefinition("Export to Synthesis", "BxD:RobotExporter:ExportRobot", CommandTypesEnum.kNonShapeEditCmdType, ClientID, null, "Export your robot's model to Synthesis.", ExportRobotIconSmall, ExportRobotIconLarge); ExportButton.OnExecute += ExportButton_OnExecute; ExportButton.OnHelp += _OnHelp; FilePanel.CommandControls.AddButton(ExportButton, true); #endregion #region DEBUG #if DEBUG DebugPanel = ExporterTab.RibbonPanels.Add("Debug", "BxD:RobotExporter:DebugPanel", ClientID); //Selection Test DedectionTestButton = ControlDefs.AddButtonDefinition("Detection Test", "BxD:RobotExporter:DetectionTestButton", CommandTypesEnum.kNonShapeEditCmdType, ClientID, null, null, DebugButtonSmall, DebugButtonLarge); DedectionTestButton.OnExecute += delegate(NameValueMap context) { if (Wizard.WizardUtilities.DetectWheels(Utilities.GUI.SkeletonBase, out List <RigidNode_Base> leftWheels, out List <RigidNode_Base> rightWheels)) { List <RigidNode_Base> allWheels = new List <RigidNode_Base>(); allWheels.AddRange(leftWheels); allWheels.AddRange(rightWheels); SelectNodes(allWheels); } }; DebugPanel.CommandControls.AddButton(DedectionTestButton, true); //UI Test UITestButton = ControlDefs.AddButtonDefinition("UI Test", "BxD:RobotExporter:UITestButton", CommandTypesEnum.kNonShapeEditCmdType, ClientID, null, null, DebugButtonSmall, DebugButtonLarge); UITestButton.OnExecute += delegate(NameValueMap context) { Wizard.WizardForm wizard = new Wizard.WizardForm(); wizard.ShowDialog(); if (Properties.Settings.Default.ShowExportOrAdvancedForm) { Form finishDialog = new Wizard.ExportOrAdvancedForm(); finishDialog.ShowDialog(); } }; DebugPanel.CommandControls.AddButton(UITestButton, true); #endif #endregion #endregion #region Final Environment Setup ExporterEnv.DefaultRibbonTab = "BxD:RobotExporter:RobotExporterTab"; MainApplication.UserInterfaceManager.ParallelEnvironments.Add(ExporterEnv); ExporterEnv.DisabledCommandList.Add(MainApplication.CommandManager.ControlDefinitions["BxD:RobotExporter:Environment"]); #endregion #region Event Handler Assignment MainApplication.UserInterfaceManager.UserInterfaceEvents.OnEnvironmentChange += UIEvents_OnEnvironmentChange; MainApplication.ApplicationEvents.OnActivateDocument += ApplicationEvents_OnActivateDocument; MainApplication.ApplicationEvents.OnDeactivateDocument += ApplicationEvents_OnDeactivateDocument; MainApplication.ApplicationEvents.OnCloseDocument += ApplicationEvents_OnCloseDocument; LegacyInterchange.LegacyEvents.RobotModified += new Action(() => { PendingChanges = true; }); #endregion #endregion Instance = this; }
private void OnEnvironmentChange(Inventor.Environment Environment, EnvironmentStateEnum EnvironmentState, EventTimingEnum BeforeOrAfter, NameValueMap Context, out HandlingCodeEnum HandlingCode) { if (BeforeOrAfter == EventTimingEnum.kAfter) { if (Environment.InternalName == Resources.IDC_ENV_INTERNAL_NAME) { if (EnvironmentState == EnvironmentStateEnum.kTerminateEnvironmentState) { if (null != FinishClickEvent) { FinishClickEvent(); } } } } else { if (Environment.InternalName == Resources.IDC_ENV_INTERNAL_NAME) { if (EnvironmentState == EnvironmentStateEnum.kActivateEnvironmentState) { mEmptyPartDoc = true; PartDocument partDoc = null; if (mInventorApp.ActiveDocumentType != DocumentTypeEnum.kPartDocumentObject) { mEmptyPartDoc = false; } else if (mInventorApp.ActiveDocumentType == DocumentTypeEnum.kPartDocumentObject) { partDoc = mInventorApp.ActiveDocument as PartDocument; if (partDoc.ComponentDefinition.SurfaceBodies.Count != 0 /*&& IsFinishFired== true*/) { mEmptyPartDoc = false; } } if (mEmptyPartDoc == false /* && IsFinishFired==false*/) { MessageBox.Show(Resources.IDC_NOT_A_NEW_PART_DOC, "Rubik's Cube", MessageBoxButtons.OK, MessageBoxIcon.Warning); HandlingCode = HandlingCodeEnum.kEventNotHandled; mPlay.Enabled = false; mScramble.Enabled = false; mSolve.Enabled = false; mNext.Enabled = false; } else if (mEmptyPartDoc == true) { if (null != ActivateClickEvent) { ActivateClickEvent(); } mPlay.Enabled = true; mScramble.Enabled = true; mSolve.Enabled = true; mNext.Enabled = true; } else { HandlingCode = HandlingCodeEnum.kEventNotHandled; return; } } } } HandlingCode = HandlingCodeEnum.kEventNotHandled; }
private void InternalSetCurrentEnvironment(Inventor.Environment environment, string editObjectId) { EnvironmentManagerInstance.SetCurrentEnvironment(environment, editObjectId); }
private void InternalGetCurrentEnvironment(out Inventor.Environment environment, out string editTargetId) { EnvironmentManagerInstance.GetCurrentEnvironment(out environment, out editTargetId); }
public void SetCurrentEnvironment(Inventor.Environment environment, string editObjectId) { InternalSetCurrentEnvironment(environment, editObjectId); }
public void GetCurrentEnvironment(out Inventor.Environment environment, out string editTargetId) { InternalGetCurrentEnvironment(out environment, out editTargetId); }