|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using System.Windows.Controls; |
| 7 | +using System.Windows.Input; |
| 8 | +using System.Windows.Media.Imaging; |
| 9 | +using Autodesk.AutoCAD.Runtime; |
| 10 | +using Autodesk.Windows; |
| 11 | + |
| 12 | +namespace CADPythonShell |
| 13 | +{ |
| 14 | + public class IronPythonConsoleApp |
| 15 | + { |
| 16 | + [CommandMethod("InitPythonConsole")] |
| 17 | + public void Execute() |
| 18 | + { |
| 19 | + CreateRibbon(); |
| 20 | + } |
| 21 | + void CreateRibbon() |
| 22 | + { |
| 23 | + RibbonControl ribbon = ComponentManager.Ribbon; |
| 24 | + if (ribbon != null) |
| 25 | + { |
| 26 | + RibbonTab rtab = ribbon.FindTab("PythonShell"); |
| 27 | + if (rtab != null) |
| 28 | + { |
| 29 | + ribbon.Tabs.Remove(rtab); |
| 30 | + } |
| 31 | + rtab = new RibbonTab(); |
| 32 | + rtab.Title = "Python Shell"; |
| 33 | + rtab.Id = "PythonShell"; |
| 34 | + //Add the Tab |
| 35 | + ribbon.Tabs.Add(rtab); |
| 36 | + addContent(rtab); |
| 37 | + } |
| 38 | + } |
| 39 | + private void addContent(RibbonTab rtab) |
| 40 | + { |
| 41 | + rtab.Panels.Add(AddOnePanel()); |
| 42 | + } |
| 43 | + static RibbonPanel AddOnePanel() |
| 44 | + { |
| 45 | + //https://forums.autodesk.com/t5/net/create-custom-ribbon-tab-and-buttons-for-autocad-mechanical-2011/td-p/2834343 |
| 46 | + RibbonPanelSource rps = new RibbonPanelSource(); |
| 47 | + rps.Title = "Autocad Python Shell"; |
| 48 | + RibbonPanel rp = new RibbonPanel(); |
| 49 | + rp.Source = rps; |
| 50 | + //Create a Command Item that the Dialog Launcher can use, |
| 51 | + // for this test it is just a place holder. |
| 52 | + RibbonButton rci = new RibbonButton(); |
| 53 | + rci.Name = "Python Shell Console"; |
| 54 | + rps.DialogLauncher = rci; |
| 55 | + //create button1 |
| 56 | + RibbonButton rb = new RibbonButton(); |
| 57 | + rb.Orientation = Orientation.Vertical; |
| 58 | + rb.AllowInStatusBar = true; |
| 59 | + rb.Size = RibbonItemSize.Large; |
| 60 | + rb.Name = "Run APS"; |
| 61 | + rb.ShowText = true; |
| 62 | + rb.Text = "Run APS"; |
| 63 | + var addinAssembly = typeof(IronPythonConsoleApp).Assembly; |
| 64 | + rb.Image = CADPythonShellApplication.GetEmbeddedPng(addinAssembly, "CADPythonShell.Resources.Python-16.png"); |
| 65 | + rb.LargeImage = CADPythonShellApplication.GetEmbeddedPng(addinAssembly, "CADPythonShell.Resources.Python-32.png"); |
| 66 | + rb.CommandHandler = new RelayCommand(new IronPythonConsoleCommand().Execute); |
| 67 | + rps.Items.Add(rb); |
| 68 | + //create button2 |
| 69 | + RibbonButton rb2 = new RibbonButton(); |
| 70 | + rb2.Orientation = Orientation.Vertical; |
| 71 | + rb2.AllowInStatusBar = true; |
| 72 | + rb2.Size = RibbonItemSize.Large; |
| 73 | + rb2.Name = "Configure APS"; |
| 74 | + rb2.ShowText = true; |
| 75 | + rb2.Text = "Configure APS"; |
| 76 | + rb2.Image = CADPythonShellApplication.GetEmbeddedPng(addinAssembly, "CADPythonShell.Resources.Settings-16.png"); |
| 77 | + rb2.LargeImage = CADPythonShellApplication.GetEmbeddedPng(addinAssembly, "CADPythonShell.Resources.Settings-32.png"); |
| 78 | + |
| 79 | + rb2.CommandHandler = new RelayCommand(new ConfigureCommand().Execute); |
| 80 | + //Add the Button to the Tab |
| 81 | + rps.Items.Add(rb2); |
| 82 | + return rp; |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments