-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.cs
133 lines (116 loc) · 4.27 KB
/
App.cs
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using Autodesk;
using Autodesk.Revit;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Events;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace DelegateTest
{
public class App : IExternalApplication
{
internal static App thisApp = null;
private Main m_MyForm;
public static UIControlledApplication UIControlApp = null;
static string AddInPath = typeof(App).Assembly.Location;
static string ButtonIconsFolder = Path.GetDirectoryName(AddInPath);
public static string AppName = Path.GetFileNameWithoutExtension(AddInPath);
public Result OnStartup(UIControlledApplication app)
{
m_MyForm = null;
thisApp = this;
UIControlApp = app;
try
{
string tabname = "MJS SYSTEM";
try { app.CreateRibbonTab(tabname); } catch { }
RibbonPanel ribbonPanel = null;
List<RibbonPanel> listRibbonPanel = app.GetRibbonPanels();
if (listRibbonPanel.Count > 0)
{
foreach (RibbonPanel rp in listRibbonPanel)
{
if (rp.Name == "MJS System")
{
ribbonPanel = rp;
break;
}
}
}
if (ribbonPanel == null)
ribbonPanel = app.CreateRibbonPanel(tabname, "Test");
if (ribbonPanel != null)
{
{
bool bFound = false;
foreach (RibbonItem item in ribbonPanel.GetItems())
{
if (item.Name == "Test_Test")
bFound = true;
}
if (!bFound)
{
PushButton pushBotton = ribbonPanel.AddItem(new PushButtonData("_____", "_____", AddInPath, "DelegateTest.Command")) as PushButton;
pushBotton.ToolTip = "Create Model";
pushBotton.LargeImage = GetBitmapSource(DelegateTest.Properties.Resources.Red_24);
//pushBotton.Image = GetBitmapSource(DataFlow.Properties.Resources.MJS);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
return Result.Succeeded;
}
public Result OnShutdown(UIControlledApplication a)
{
if (m_MyForm != null && !m_MyForm.Visible)
{
m_MyForm.Close();
}
return Result.Succeeded;
}
public void ShowForm(UIApplication uiapp)
{
if (m_MyForm == null || m_MyForm.IsDisposed)
{
RequestHandler handler = new RequestHandler();
ExternalEvent exEvent = ExternalEvent.Create(handler);
m_MyForm = new Main(exEvent, handler);
m_MyForm.Show();
}
}
public void WakeFormUp()
{
if (m_MyForm != null)
{
m_MyForm.WakeUp();
}
}
private System.Windows.Media.Imaging.BitmapSource GetBitmapSource(System.Drawing.Bitmap _image)
{
System.Drawing.Bitmap bitmap = _image;
BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
bitmap.GetHbitmap(),
System.IntPtr.Zero,
System.Windows.Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
return bitmapSource;
}
}
}