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