Skip to content

Commit c9a172e

Browse files
1st commit
0 parents  commit c9a172e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+14048
-0
lines changed

.gitignore

Lines changed: 492 additions & 0 deletions
Large diffs are not rendered by default.

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"dotnet.preferCSharpExtension": true
3+
}

AlibreAddOn.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using AlibreAddOn;
2+
using AlibrePythonShell;
3+
using AlibreX;
4+
using System;
5+
namespace AlibreAddOnAssembly
6+
{
7+
public static class AlibreAddOn
8+
{
9+
private static IADRoot AlibreRoot { get; set; }
10+
private static IntPtr _parentWinHandle;
11+
private static AlibrePythonShellAddon.AlibrePythonShellAddon _laucherAddonHandle;
12+
13+
public static void AddOnLoad(IntPtr hwnd, IAutomationHook pAutomationHook, IntPtr unused)
14+
{
15+
AlibreRoot = (IADRoot) pAutomationHook.Root;
16+
_parentWinHandle = hwnd;
17+
_laucherAddonHandle = new AlibrePythonShellAddon.AlibrePythonShellAddon(AlibreRoot, _parentWinHandle);
18+
IADSession currentSession = AlibreRoot.TopmostSession;
19+
var PythonShell = new MainWindow(currentSession);
20+
var winform = new Form1(currentSession);
21+
winform.Show();
22+
}
23+
public static IADRoot GetRoot()
24+
{
25+
return AlibreRoot;
26+
}
27+
public static void AddOnInvoke
28+
(
29+
IntPtr hwnd,
30+
IntPtr pAutomationHook,
31+
string sessionName,
32+
bool isLicensed,
33+
int reserved1,
34+
int reserved2)
35+
{
36+
}
37+
public static void AddOnUnload
38+
(
39+
IntPtr hwnd,
40+
bool forceUnload,
41+
ref bool cancel,
42+
int reserved1,
43+
int reserved2)
44+
{
45+
}
46+
public static IAlibreAddOn GetAddOnInterface()
47+
{
48+
return (IAlibreAddOn)_laucherAddonHandle;
49+
}
50+
}
51+
}

AlibrePython/Host/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import AlibreX
2+
import AlibreScript.API
3+
### init scriptcontext
4+
# the offical Rhino.Python.Host module can not working in this environment.
5+
# reimplement Rhino.Python.Host.Coerce3dPointFromEnumerables function.
6+
# import RhinoPython.Host
7+
# def Coerce3dPointFromEnumerables(point):
8+
# return Rhino.Geometry.Point3d(point[0],point[1],point[2])

AlibrePython/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import AlibreX
2+
import AlibreScript.API
3+
### init scriptcontext
4+
# the offical Rhino.Python.Host module can not working in this environment.
5+
# reimplement Rhino.Python.Host.Coerce3dPointFromEnumerables function.
6+
# import RhinoPython.Host
7+
# def Coerce3dPointFromEnumerables(point):
8+
# return Rhino.Geometry.Point3d(point[0],point[1],point[2])

AlibrePythonShellAddon.adc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<AlibreDesignAddOn specificationVersion="2" friendlyName="AlibrePythonShellAddon 1">
2+
<Author name="AuthorName" link="https://github.com/Testbed-for-Alibre-Design/AlibrePythonShell"/>
3+
<Copyright>Copyright (c) 2023</Copyright>
4+
<DLL type="Managed" loadedWhen="Startup" location="AlibrePythonShell.dll"/>
5+
<Icon location="logo.ico"/>
6+
<Menu text="AlibrePythonShellAddon 1"/>
7+
<Description>AlibrePythonShellAddon</Description>
8+
<Workspace type="Always"/>
9+
<Property name="Identifier" value="AlibrePythonShellAddon"/>
10+
</AlibreDesignAddOn>

AlibrePythonShellAddon.cs

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Windows.Forms;
5+
using AlibreAddOn;
6+
using AlibreX;
7+
using AlibrePythonShell;
8+
using System.Windows;
9+
using System.Threading;
10+
using System.Windows.Threading;
11+
12+
13+
namespace AlibrePythonShellAddon
14+
{
15+
public class AlibrePythonShellAddon : IAlibreAddOn
16+
{
17+
private const int MenuIdRoot = 401;
18+
private const int MenuIdUtils = 601;
19+
private int[] _menuIdsRoot;
20+
private IADRoot _alibreRoot;
21+
private readonly IntPtr _parentWinHandle;
22+
public AlibrePythonShellAddon(IADRoot alibreRoot, IntPtr parentWinHandle)
23+
{
24+
_alibreRoot = alibreRoot;
25+
_parentWinHandle = parentWinHandle;
26+
27+
//PythonShell.Topmost = true;
28+
BuildMenuTree();
29+
}
30+
public int RootMenuItem => MenuIdRoot;
31+
private void BuildMenuTree()
32+
{
33+
_menuIdsRoot = new int[1]
34+
{
35+
MenuIdUtils
36+
};
37+
}
38+
public bool HasSubMenus(int menuId)
39+
{
40+
switch (menuId)
41+
{
42+
case MenuIdRoot: return true;
43+
}
44+
return false;
45+
}
46+
public Array SubMenuItems(int menuId)
47+
{
48+
switch (menuId)
49+
{
50+
case MenuIdRoot: return _menuIdsRoot;
51+
}
52+
return null;
53+
}
54+
public string MenuItemText(int menuId)
55+
{
56+
switch (menuId)
57+
{
58+
case MenuIdRoot: return "Global IronPython Console";
59+
}
60+
return "Global IronPython Console";
61+
}
62+
public bool PopupMenu(int menuId)
63+
{
64+
return false;
65+
}
66+
public ADDONMenuStates MenuItemState(int menuId, string sessionIdentifier)
67+
{
68+
var session = _alibreRoot.Sessions.Item(sessionIdentifier);
69+
switch (session)
70+
{
71+
case IADDrawingSession:
72+
switch (menuId)
73+
{
74+
case MenuIdRoot: return ADDONMenuStates.ADDON_MENU_ENABLED;
75+
}
76+
break;
77+
case IADAssemblySession:
78+
switch (menuId)
79+
{
80+
case MenuIdRoot: return ADDONMenuStates.ADDON_MENU_ENABLED;
81+
}
82+
break;
83+
case IADPartSession:
84+
switch (menuId)
85+
{
86+
case MenuIdRoot: return ADDONMenuStates.ADDON_MENU_ENABLED;
87+
}
88+
break;
89+
}
90+
return ADDONMenuStates.ADDON_MENU_ENABLED;
91+
}
92+
public string MenuItemToolTip(int menuId)
93+
{
94+
switch (menuId)
95+
{
96+
case MenuIdUtils: return "Global IronPython Console";
97+
}
98+
return "";
99+
}
100+
public string MenuIcon(int menuId)
101+
{
102+
switch (menuId)
103+
{
104+
case MenuIdUtils: return "logo.ico";
105+
}
106+
return "Global IronPython Console";
107+
}
108+
public bool HasPersistentDataToSave(string sessionIdentifier)
109+
{
110+
return false;
111+
}
112+
public IAlibreAddOnCommand InvokeCommand(int menuId, string sessionIdentifier)
113+
{
114+
var session = _alibreRoot.Sessions.Item(sessionIdentifier);
115+
switch (menuId)
116+
{
117+
case MenuIdUtils:
118+
{
119+
return LauncherAddonCmd(session);
120+
}
121+
}
122+
return null;
123+
}
124+
private void OpenNewWindowOnSeparateThread()
125+
{
126+
127+
}
128+
private IAlibreAddOnCommand LauncherAddonCmd(IADSession currentSession)
129+
{
130+
131+
System.Windows.MessageBox.Show("AlibrePythonShell Addon", "Global IronPython ConsoleCommand");
132+
133+
//Window cliW = new IronPython.
134+
135+
Window PythonShell = new MainWindow(currentSession);
136+
PythonShell.ShowDialog();
137+
//PythonShell.ShowDialog();
138+
//PythonShell.Topmost = true;
139+
// Create a new thread;
140+
141+
return null;
142+
}
143+
public void SaveData(IStream pCustomData, string sessionIdentifier)
144+
{
145+
}
146+
public void setIsAddOnLicensed(bool isLicensed)
147+
{
148+
}
149+
public bool UseDedicatedRibbonTab()
150+
{
151+
return true;
152+
}
153+
public void LoadData(IStream pCustomData, string sessionIdentifier)
154+
{
155+
throw new NotImplementedException();
156+
}
157+
}
158+
}

0 commit comments

Comments
 (0)