public void LoadPreviewIcon() { var iconCamera = RobotExporterAddInServer.Instance.Application.TransientObjects.CreateCamera(); iconCamera.SceneObject = RobotExporterAddInServer.Instance.OpenAssemblyDocument.ComponentDefinition; const double zoom = 0.6; // Zoom, where a zoom of 1 makes the camera the size of the whole robot const int widthConst = 3; // The image needs to be wide to hide the XYZ coordinate labels in the bottom left corner var occurrences = InventorUtils.GetComponentOccurrencesFromNodes(new List <RigidNode_Base> { node }); iconCamera.Fit(); iconCamera.GetExtents(out _, out var height); InventorUtils.SetCameraView(InventorUtils.GetOccurrencesCenter(occurrences), 15, height * zoom * widthConst, height * zoom, iconCamera); pictureBox1.Image = AxHostConverter.PictureDispToImage( iconCamera.CreateImage(pictureBox1.Height * widthConst, pictureBox1.Height, RobotExporterAddInServer.Instance.Application.TransientObjects.CreateColor(210, 222, 239), RobotExporterAddInServer.Instance.Application.TransientObjects.CreateColor(175, 189, 209))); }
public stdole.IPictureDisp catGallery_getItemImage(Office.IRibbonControl control, int index) { Category cat = sorted_cats.ElementAt(index); Rectangle rect = new Rectangle(0, 0, 20, 20); Bitmap img = new Bitmap(rect.Width, rect.Height); Graphics gr = Graphics.FromImage(img); // draw the interior with category color rect.Inflate(-4, -4); Brush b1 = new SolidBrush(ColorTranslator.FromOle((int)cat.CategoryGradientBottomColor)); gr.FillRectangle(b1, rect); Pen p1 = new Pen(ColorTranslator.FromOle((int)cat.CategoryBorderColor), 1); gr.DrawRectangle(p1, rect); rect.Inflate(3, 3); Pen p2 = new Pen(Color.MediumBlue, 1); if (catsAllHave.Contains(cat.Name)) { gr.DrawRectangle(p2, rect); } else if (catsSomeHave.Contains(cat.Name)) { p2.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; gr.DrawRectangle(p2, rect); } return(AxHostConverter.ImageToPictureDisp(img)); }
private void CreateRibbon() { try { Inventor.UserInterfaceManager userInterFaceMgr = mInventorApp.UserInterfaceManager; userInterFaceMgr.UserInterfaceEvents.OnEnvironmentChange += new UserInterfaceEventsSink_OnEnvironmentChangeEventHandler(OnEnvironmentChange); //retrieve the GUID for this class GuidAttribute addInCLSID = (GuidAttribute)GuidAttribute.GetCustomAttribute(typeof(RubiksCube.RubiksAddInServer), typeof(GuidAttribute)); string clientId = "{" + addInCLSID.Value + "}"; Icon appLarge = Resources.Rubiks_Cube_32; object applargeIcon = AxHostConverter.ImageToPictureDisp(appLarge.ToBitmap()); Icon appStand = Resources.Rubiks_Cube_16; object appStandIcon = AxHostConverter.ImageToPictureDisp(appStand.ToBitmap()); Environments envs = userInterFaceMgr.Environments; mEnvironment = envs.Add(Resources.IDC_ENV_DISPLAY_NAME, Resources.IDC_ENV_INTERNAL_NAME, null, appStandIcon, applargeIcon); mEnvironment.AdditionalVisibleRibbonTabs = new string[] { Resources.IDC_ENV_INTERNAL_NAME }; mObjCollection = mInventorApp.TransientObjects.CreateObjectCollection(); //get the ribbon associated with part document Inventor.Ribbons ribbons = userInterFaceMgr.Ribbons; mPartRibbon = ribbons[Resources.IDC_ENV_PART]; //get the tabs associated with part ribbon Inventor.RibbonTabs rubikRibbonTabs = mPartRibbon.RibbonTabs; mRubiksPartTab = rubikRibbonTabs.Add(Resources.IDC_TAB_DISPLAY_NAME, Resources.IDC_TAB_INTERNAL_NAME, "F0911DF2-478B-49EC-808D-D7C1F5271B6D", Resources.IDC_TARGET_TAB_NAME, true, true); //Adding solve Panel. RibbonPanel solvePanel = mRubiksPartTab.RibbonPanels.Add(Resources.IDC_SOLVE_DISPLAY_NAME, Resources.IDC_SOLVE_INTERNAL_NAME, "60A50C33-F7EE-4B74-BCB0-C5CE03C1B3E6"); Inventor.CommandControl solveControl = solvePanel.CommandControls.AddButton(mSolve, true, true); //Adding randomize Panel. RibbonPanel scramblePanel = mRubiksPartTab.RibbonPanels.Add(Resources.IDC_SCRAMBLE_DISPLAY_NAME, Resources.IDC_SCRAMBLE_INTERNAL_NAME, "D20674CE-A855-4403-850B-FDE59C4A167B"); Inventor.CommandControl scrambleControl = scramblePanel.CommandControls.AddButton(mScramble, true, true); //Adding randomize Panel. RibbonPanel playPanel = mRubiksPartTab.RibbonPanels.Add(Resources.IDC_PLAY_DISPLAY_NAME, Resources.IDC_PLAY_INTERNAL_NAME, "343D703C-1194-4715-BF54-3BE4E3B9FF64"); //Inventor.CommandControl playControl = playPanel.CommandControls.AddButton(mPlay, true, true, "", false); mObjCollection.Add(mPlay); mObjCollection.Add(mNext); CommandControl partCmdCtrl = playPanel.CommandControls.AddSplitButtonMRU(mObjCollection, true); mEnvironment.DefaultRibbonTab = Resources.IDC_TAB_INTERNAL_NAME; userInterFaceMgr.ParallelEnvironments.Add(mEnvironment); mEnvCtrlDef = mInventorApp.CommandManager.ControlDefinitions[Resources.IDC_ENV_INTERNAL_NAME]; mEnvCtrlDef.ProgressiveToolTip.ExpandedDescription = Resources.IDC_APPLICATION_BTN_TOOLTIP_EXPANDED; mEnvCtrlDef.ProgressiveToolTip.Description = Resources.IDC_APPLICATION_BTN_TOOLTIP_DESCRIPTION; mEnvCtrlDef.ProgressiveToolTip.Title = Resources.IDC_APPLICATION_BTN_TITLE; AddToDisabledList(); } catch (Exception e) { MessageBox.Show(e.InnerException.Message); } }
private void CreateApplicationBtn() { Icon mainLarge = Resources.Rubiks_Cube_32; object mainLargeIcon = AxHostConverter.ImageToPictureDisp(mainLarge.ToBitmap()); Icon mainStand = Resources.Rubiks_Cube_16; object mainStandIcon = AxHostConverter.ImageToPictureDisp(mainStand.ToBitmap()); mApplicationBtn = mInventorApp.CommandManager.ControlDefinitions.AddButtonDefinition(Resources.IDC_ENV_DISPLAY_NAME, Resources.IDC_ENV_DISPLAY_NAME, Inventor.CommandTypesEnum.kQueryOnlyCmdType, Resources.IDC_EMPTY, Resources.IDC_EMPTY, "", mainStandIcon, mainLargeIcon); mApplicationBtn.OnHelp += new ButtonDefinitionSink_OnHelpEventHandler(OnHelpButtonClick); mApplicationBtn.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(OnRubikClick); }
private void CreateSolvepanel() { Icon settingsLarge = Resources.Solve_32; object settingsLargeIcon = AxHostConverter.ImageToPictureDisp(settingsLarge.ToBitmap()); Icon settingsStand = Resources.Solve_16; object settingsStandIcon = AxHostConverter.ImageToPictureDisp(settingsStand.ToBitmap()); mSolve = mInventorApp.CommandManager.ControlDefinitions.AddButtonDefinition(Resources.IDC_SOLVE_DISPLAY_NAME, Resources.IDC_SOLVE_INTERNAL_NAME, Inventor.CommandTypesEnum.kQueryOnlyCmdType, Resources.IDC_EMPTY, Resources.IDC_EMPTY, Resources.IDC_EMPTY, settingsStandIcon, settingsLargeIcon); mSolve.OnExecute += new Inventor.ButtonDefinitionSink_OnExecuteEventHandler(OnSolve); mSolve.OnHelp += new ButtonDefinitionSink_OnHelpEventHandler(OnHelpButtonClick); mSolve.ProgressiveToolTip.Title = Resources.IDC_SOLVE_DISPLAY_NAME; mSolve.ProgressiveToolTip.Description = Resources.IDC_SOLVE_BTN_TOOLTIP_DESCRIPTION; mSolve.ProgressiveToolTip.ExpandedDescription = Resources.IDC_SOLVE_BTN_TOOLTIP_EXPANDED; }
private void CreateNextPanel() { Icon CalibrationLarge = Resources.Next_32; object CalibrationLargeIcon = AxHostConverter.ImageToPictureDisp(CalibrationLarge.ToBitmap()); Icon CalibrationStand = Resources.Next_16; object CalibrationStandIcon = AxHostConverter.ImageToPictureDisp(CalibrationLarge.ToBitmap()); mNext = mInventorApp.CommandManager.ControlDefinitions.AddButtonDefinition(Resources.IDC_NEXT_DISPLAY_NAME, Resources.IDC_NEXT_INTERNAL_NAME, Inventor.CommandTypesEnum.kQueryOnlyCmdType, Resources.IDC_EMPTY, Resources.IDC_EMPTY, Resources.IDC_EMPTY, CalibrationStandIcon, CalibrationLargeIcon); mNext.OnExecute += new Inventor.ButtonDefinitionSink_OnExecuteEventHandler(OnNext); mNext.OnHelp += new ButtonDefinitionSink_OnHelpEventHandler(OnHelpButtonClick); mNext.ProgressiveToolTip.Title = Resources.IDC_NEXT_DISPLAY_NAME; mNext.ProgressiveToolTip.Description = Resources.IDC_NEXT_BTN_TOOLTIP_DESCRIPTION; mNext.ProgressiveToolTip.ExpandedDescription = Resources.IDC_NEXT_BTN_TOOLTIP_EXPANDED; }
private void GetIconPicture(string standardPictureName, string largePictureName) { oIPictureDispStandard = null; oIPictureDispLarge = null; //get the original picture System.IO.Stream oStream_s = assembly.GetManifestResourceStream(standardPictureName); System.IO.Stream oStream_l = assembly.GetManifestResourceStream(largePictureName); //instant icon object,get original source System.Drawing.Icon oIcon_s = new System.Drawing.Icon(oStream_s); System.Drawing.Icon oIcon_l = new System.Drawing.Icon(oStream_l); //call ImageToPictureDisp convertion method oIPictureDispStandard = AxHostConverter.ImageToPictureDisp(oIcon_s.ToBitmap()); oIPictureDispLarge = AxHostConverter.ImageToPictureDisp(oIcon_l.ToBitmap()); }
public static void UseApprentice(object obj) { MainForm form1 = (MainForm)obj; Inventor.ApprenticeServerComponent app = new Inventor.ApprenticeServerComponent(); string folder = @"C:\Users\adamnagy\Documents\Inventor"; UpdateInfo(form1.lblInfo, "Working..."); string [] files = Directory.GetFiles(folder, "*.ipt"); int i = 0; foreach (string file in files) { Inventor.ApprenticeServerDocument doc = app.Open(file); UpdateInfo(form1.lblInfo, "Working..." + (++i).ToString()); try { var pic = doc.Thumbnail; System.Diagnostics.Debug.WriteLine("Got Thumbnail"); Image img = AxHostConverter.PictureDispToImage(pic); form1.pictureBox.Image = null; //System.Threading.Thread.Sleep(100); form1.pictureBox.Image = img; //System.Threading.Thread.Sleep(100); } catch { System.Diagnostics.Debug.WriteLine("Oops"); UpdateInfo(form1.lblInfo, "Oops..."); return; } doc.Close(); } UpdateInfo(form1.lblInfo, "Done"); }
/// <summary> /// Creates a transparent <see cref="IPictureDisp"/> icon for the specified <see cref="CommandBarButton"/>. /// </summary> public static void SetButtonImage(CommandBarButton button, Image image, Image mask) { button.FaceId = 0; if (image == null || mask == null) { return; } try { button.Picture = AxHostConverter.ImageToPictureDisp(image); button.Mask = AxHostConverter.ImageToPictureDisp(mask); } catch (COMException exception) { Debug.Print("Button image could not be set for button [" + button.Caption + "]\n" + exception); } }
/// <summary> /// gets icons from embedded resources and converts them to objects /// </summary> private void getIcons() { //get current assembly Assembly thisDll = Assembly.GetExecutingAssembly(); //get icon streams Stream plus16stream = thisDll.GetManifestResourceStream("InvAddIn.img.plus16.ico"); Stream plus128stream = thisDll.GetManifestResourceStream("InvAddIn.img.plus128.ico"); Stream gear16stream = thisDll.GetManifestResourceStream("InvAddIn.img.gear16.ico"); Stream gear128stream = thisDll.GetManifestResourceStream("InvAddIn.img.gear16.ico"); //get icons Icon plus16icon = new Icon(plus16stream); Icon plus128icon = new Icon(plus128stream); Icon gear16icon = new Icon(gear16stream); Icon gear128icon = new Icon(gear128stream); //convert to objects plus16obj = AxHostConverter.ImageToPictureDisp(plus16icon.ToBitmap()); plus128obj = AxHostConverter.ImageToPictureDisp(plus128icon.ToBitmap()); gear16obj = AxHostConverter.ImageToPictureDisp(gear16icon.ToBitmap()); gear128obj = AxHostConverter.ImageToPictureDisp(gear128icon.ToBitmap()); }
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); }
//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 static void SetButtonImage(CommandBarButton button, Bitmap image, Bitmap mask) { button.FaceId = 0; button.Picture = AxHostConverter.ImageToPictureDisp(image); button.Mask = AxHostConverter.ImageToPictureDisp(mask); }
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); }