/
AlibreExportOpen.cs
213 lines (179 loc) · 6.61 KB
/
AlibreExportOpen.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using AlibreAddOn;
using AlibreX;
namespace AlibreExportOpen
{
public class AlibreExportOpen : IAlibreAddOn
{
private const int MenuIdRoot = 401;
private const int MenuIdSample = 402;
private readonly int[] _menuIdsBase = new int[1]
{
MenuIdSample
};
private IADRoot _alibreRoot;
private IntPtr _parentWinHandle;
private bool _useSvgIcons;
public AlibreExportOpen(IADRoot alibreRoot, IntPtr parentWinHandle)
{
_alibreRoot = alibreRoot;
_parentWinHandle = parentWinHandle;
string version = _alibreRoot.Version.Replace("PRODUCTVERSION ", "");
string[] versionarr = version.Split(',');
int majorVersion = int.Parse(versionarr[0]);
_useSvgIcons = majorVersion > 25;
}
#region Menus
/// <summary>
/// Returns the menu ID of the add-on's root menu item
/// </summary>
public int RootMenuItem => MenuIdRoot;
/// <summary>
/// Description("Returns Whether the given Menu ID has any sub menus")
/// </summary>
/// <param name="menuId"></param>
/// <returns></returns>
public bool HasSubMenus(int menuId)
{
// return false;
return menuId == MenuIdRoot;
}
/// <summary>
/// Returns the ID's of sub menu items under a popup menu item; the menu ID of a 'leaf' menu becomes its command ID
/// </summary>
/// <param name="menuId"></param>
/// <returns></returns>
public Array SubMenuItems(int menuId)
{
return _menuIdsBase;
}
/// <summary>
/// Returns the display name of a menu item; a menu item with text of a single dash (“-“) is a separator
/// </summary>
/// <param name="menuId"></param>
/// <returns></returns>
public string MenuItemText(int menuId)
{
return "Export, Open .stl";
}
/// <summary>
/// Returns True if input menu item has sub menus // seems odd given name of method
/// </summary>
/// <param name="menuId"></param>
/// <returns></returns>
public bool PopupMenu(int menuId)
{
return true;
}
/// <summary>
/// Returns property bits providing information about the state of a menu item
/// ADDON_MENU_ENABLED = 1,
/// ADDON_MENU_GRAYED = 2,
/// ADDON_MENU_CHECKED = 3,
/// ADDON_MENU_UNCHECKED = 4,
/// </summary>
/// <param name="menuId"></param>
/// <param name="sessionIdentifier"></param>
/// <returns></returns>
public ADDONMenuStates MenuItemState(int menuId, string sessionIdentifier)
{
var session = _alibreRoot.Sessions.Item(sessionIdentifier);
switch (session)
{
case IADAssemblySession: return ADDONMenuStates.ADDON_MENU_ENABLED;
case IADPartSession: return ADDONMenuStates.ADDON_MENU_ENABLED;
}
return ADDONMenuStates.ADDON_MENU_GRAYED;
}
/// <summary>
/// Returns a tool tip string if input menu ID is that of a 'leaf' menu item
/// </summary>
/// <param name="menuId"></param>
/// <returns></returns>
public string MenuItemToolTip(int menuId)
{
return "Export,Open .stl";
}
/// <summary>
/// Returns the icon name (with extension) for a menu item; the icon will be searched under the folder where the add-on's .adc file is present
/// </summary>
/// <param name="menuId"></param>
/// <returns></returns>
public string MenuIcon(int menuId)
{
return _useSvgIcons ? "3DPrint.svg" : "3DPrint.ico";
}
/// <summary>
/// Returns True if AddOn has updated Persistent Data
/// </summary>
/// <param name="sessionIdentifier"></param>
/// <returns></returns>
public bool HasPersistentDataToSave(string sessionIdentifier)
{
return false;
}
/// <summary>
/// Invokes the add-on command identified by menu ID; returning the add-on command interface is optional
/// </summary>
/// <param name="menuId"></param>
/// <param name="sessionIdentifier"></param>
/// <returns></returns>
public IAlibreAddOnCommand InvokeCommand(int menuId, string sessionIdentifier)
{
var session = _alibreRoot.Sessions.Item(sessionIdentifier);
return DoExport(session);
// return DoSample(session);
}
#endregion
#region Export
private IAlibreAddOnCommand DoExport(IADSession currentSession)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Standard Tessellation Language|*.stl";
saveFileDialog1.Title = "Save a 3D File";
saveFileDialog1.FileName = currentSession.Name + ".stl";
DialogResult dr= saveFileDialog1.ShowDialog();
if (dr==DialogResult.OK)
{
((IADDesignSession)currentSession).ExportSTL2(saveFileDialog1.FileName);
System.Diagnostics.Process.Start(Path.GetFullPath(saveFileDialog1.FileName));
}
return null;
}
#endregion
/// <summary>
/// Loads Data from AddOn
/// </summary>
/// <param name="pCustomData"></param>
/// <param name="sessionIdentifier"></param>
public void LoadData(IStream pCustomData, string sessionIdentifier)
{
}
/// <summary>
/// Saves Data to AddOn
/// </summary>
/// <param name="pCustomData"></param>
/// <param name="sessionIdentifier"></param>
public void SaveData(IStream pCustomData, string sessionIdentifier)
{
}
/// <summary>
/// Sets the IsLicensed bit for the tightly coupled Add-on
/// </summary>
/// <param name="isLicensed"></param>
public void setIsAddOnLicensed(bool isLicensed)
{
}
/// <summary>
/// Returns True if the AddOn needs to use a Dedicated Ribbon Tab
/// </summary>
/// <returns></returns>
public bool UseDedicatedRibbonTab()
{
return true;
}
}
}