-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateCustomTaskpane.cs
90 lines (70 loc) · 2.83 KB
/
CreateCustomTaskpane.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
using Microsoft.Win32;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swpublished;
using System;
using System.Runtime.InteropServices;
namespace CustomTaskpane
{
public class CreateCustomTaskpane : ISwAddin
{
#region Private Members
public SldWorks swApp;
private int mSwCookie;
private TaskpaneView mTaskpaneView;
#endregion Private Members
#region Public Members
public const string PROG_ID = "My Solidworks Add-in";
#endregion
#region Solidworks Add-In Callbacks
bool ISwAddin.ConnectToSW(object ThisSW, int Cookie)
{
swApp = (SldWorks)ThisSW;
mSwCookie = Cookie;
_ = swApp.SetAddinCallbackInfo2(0, this, mSwCookie);
#region Create UI
string[] bitmap = new string[6];
string toolTip = "Phan Nguyen Ngoc Hien | Solidworks Expert";
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string directory = Directory.GetParent(assemblyFolder).Parent.FullName + "\\Resources\\";
bitmap[0] = directory + "logo_large20x20.png";
bitmap[1] = directory + "logo_large32x32.png";
bitmap[2] = directory + "logo_large40x40.png";
bitmap[3] = directory + "logo_large64x64.png";
bitmap[4] = directory + "logo_large96x96.png";
bitmap[5] = directory + "logo_large128x128.png";
mTaskpaneView = swApp.CreateTaskpaneView3(bitmap, toolTip);
mTaskpaneView.AddControl(PROG_ID, string.Empty);
#endregion
return true;
}
bool ISwAddin.DisconnectFromSW()
{
#region Exit UI
mTaskpaneView.DeleteView();
Marshal.ReleaseComObject(mTaskpaneView);
mTaskpaneView = null;
#endregion
return true;
}
#endregion Solidworks Add-In callbacks
#region COM Registration
[ComRegisterFunction]
public static void RegisterFunction(Type t)
{
RegistryKey mLocalMachine = Registry.LocalMachine;
string subKey = "SOFTWARE\\SOLIDWORKS\\ADDINS\\{" + t.GUID.ToString() + "}";
RegistryKey mRegistryKey = mLocalMachine.CreateSubKey(subKey);
mRegistryKey.SetValue(null, 0);
mRegistryKey.SetValue("Description", "My Solidworks Add-In");
mRegistryKey.SetValue("Title", "My Task pane");
}
[ComUnregisterFunction]
public static void UnregisterFunction(Type t)
{
RegistryKey mLocalMachine = Registry.LocalMachine;
string subkey = "SOFTWARE\\SOLIDWORKS\\ADDINS\\{" + t.GUID.ToString() + "}";
mLocalMachine.DeleteSubKey(subkey);
}
#endregion COM Registration
}
}