Skip to content

Commit e4d09e3

Browse files
committed
Udpate start up for Alias 2027.1 support. Add python plugin for 2027.1
1 parent 59738ca commit e4d09e3

3 files changed

Lines changed: 162 additions & 6 deletions

File tree

plugins/FlowToolkitAliasPlugin.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
from __future__ import annotations
2+
3+
import os
4+
import sys
5+
6+
# Add the framework path to sys.path for Alias's embedded Python interpreter
7+
_fw_path = os.environ.get("TK_FRAMEWORK_ALIAS_PYTHON_PATH")
8+
print(f"TK_FRAMEWORK_ALIAS_PYTHON_PATH: {_fw_path}")
9+
if _fw_path and _fw_path not in sys.path:
10+
sys.path.insert(0, _fw_path)
11+
12+
try:
13+
import alias_api as alpy
14+
except ImportError:
15+
import alias_api_d as alpy
16+
17+
from tk_framework_alias.server import AliasBridge
18+
19+
PLUGIN_VERSION = "dev"
20+
21+
_alias_bridge: AliasBridge | None = None
22+
23+
24+
@alpy.plugin(
25+
name="Flow Toolkit",
26+
description="Flow Production Tracking integration for Alias",
27+
author="Autodesk",
28+
version="0.1",
29+
)
30+
class FlowToolkitAliasPlugin:
31+
"""Register the Flow Toolkit plugin with Alias."""
32+
33+
34+
@alpy.continuous_tool(menu=alpy.palette.PICK)
35+
class FlowToolkitTool:
36+
"""Placeholder tool required by Alias plugin parser."""
37+
38+
@alpy.tool_init(
39+
manipulates_pick_list=False, coordinate_type=alpy.COORDINATE_ABSOLUTE
40+
)
41+
def on_tool_begin(self):
42+
pass
43+
44+
@alpy.tool_cleanup
45+
def on_tool_end(self):
46+
pass
47+
48+
49+
@alpy.plugin_init
50+
def initialize():
51+
"""Start the AliasBridge server and bootstrap the client application."""
52+
global _alias_bridge
53+
54+
_alias_bridge = AliasBridge()
55+
56+
hostname = os.environ.get("ALIAS_PLUGIN_CLIENT_SIO_HOSTNAME")
57+
port_str = os.environ.get("ALIAS_PLUGIN_CLIENT_SIO_PORT")
58+
port = int(port_str) if port_str else -1
59+
60+
max_retries = 0 if (hostname and port >= 0) else -1
61+
62+
if not _alias_bridge.start_server(hostname, port, max_retries):
63+
print("Failed to start Alias communication")
64+
return
65+
66+
print("Running Alias Python API server")
67+
68+
client_name = os.environ.get("ALIAS_PLUGIN_CLIENT_NAME", "plugin-client")
69+
70+
client_info = {
71+
"plugin_version": PLUGIN_VERSION,
72+
"alias_version": getattr(alpy, "__version__", "unknown"),
73+
"python_version": sys.version,
74+
}
75+
76+
if _alias_bridge.bootstrap_client(client_name, client_info):
77+
print(f"Starting client '{client_name}'...")
78+
79+
80+
@alpy.plugin_exit
81+
def deinit():
82+
"""Stop the AliasBridge server."""
83+
global _alias_bridge
84+
85+
if _alias_bridge:
86+
try:
87+
_alias_bridge.stop_server()
88+
except Exception as exc:
89+
print(str(exc))
90+
91+
_alias_bridge = None

plugins/temp/flow_toolkit.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from __future__ import annotations
2+
3+
import os
4+
import sys
5+
6+
# Add the framework path to sys.path for Alias's embedded Python interpreter
7+
_fw_path = os.environ.get("TK_FRAMEWORK_ALIAS_PYTHON_PATH")
8+
print(f"TK_FRAMEWORK_ALIAS_PYTHON_PATH: {_fw_path}")
9+
if _fw_path and _fw_path not in sys.path:
10+
sys.path.insert(0, _fw_path)
11+
12+
import alias_api as alpy
13+
14+
from tk_framework_alias.server import AliasBridge
15+
16+
PLUGIN_VERSION = "dev"
17+
18+
19+
def start():
20+
"""Start the AliasBridge server and bootstrap the client application."""
21+
22+
alias_bridge = AliasBridge()
23+
24+
hostname = os.environ.get("ALIAS_PLUGIN_CLIENT_SIO_HOSTNAME")
25+
port_str = os.environ.get("ALIAS_PLUGIN_CLIENT_SIO_PORT")
26+
port = int(port_str) if port_str else -1
27+
28+
max_retries = 0 if (hostname and port >= 0) else -1
29+
30+
if not alias_bridge.start_server(hostname, port, max_retries):
31+
print("Failed to start Alias communication")
32+
return None
33+
34+
print("Running Alias Python API server")
35+
36+
client_name = os.environ.get("ALIAS_PLUGIN_CLIENT_NAME", "plugin-client")
37+
38+
client_info = {
39+
"plugin_version": PLUGIN_VERSION,
40+
"alias_version": getattr(alpy, "__version__", "unknown"),
41+
"python_version": sys.version,
42+
}
43+
44+
if alias_bridge.bootstrap_client(client_name, client_info):
45+
print(f"Starting client '{client_name}'...")
46+
47+
return alias_bridge
48+
49+
50+
alias_bridge = start()

startup.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ def prepare_launch(self, exec_path, args, file_to_open=None):
127127
required_env.update(plugin_env)
128128
required_env["PYTHONPATH"] = os.environ["PYTHONPATH"]
129129

130+
# Pass the framework path explicitly for the embedded Python plugin,
131+
# which cannot safely use the full PYTHONPATH (stdlib version conflicts).
132+
required_env["TK_FRAMEWORK_ALIAS_PYTHON_PATH"] = framework_python_path
133+
130134
# Prepare the launch environment with variables required by the
131135
# classic bootstrap approach.
132136
required_env["SGTK_ENGINE"] = self.engine_name
@@ -141,6 +145,15 @@ def prepare_launch(self, exec_path, args, file_to_open=None):
141145
if file_to_open:
142146
required_env["SGTK_FILE_TO_OPEN"] = file_to_open
143147

148+
if not plugin_file_path:
149+
# No C++ plugin, use our Python plugin
150+
required_env["ALIAS_INTERNAL_PYTHON_SCRIPT_FOLDER"] = os.path.join(
151+
self.disk_location, "plugins"
152+
)
153+
# FIXME default to 0
154+
alias_debug = os.environ.get("TK_ALIAS_DEBUG_CONSOLE", "1")
155+
required_env["ALIAS_DEBUG_CONSOLE"] = alias_debug
156+
144157
# Get the launch app path and args
145158
app_path, app_args = self.__prepare_launch_args(
146159
args, code_name, plugin_file_path, exec_path, server_python_exe
@@ -342,7 +355,7 @@ def __prepare_launch_args(
342355
:type args: str
343356
:parm code_name: The Alias code name.
344357
:type code_name: str
345-
:parm plugin_file_path: The file path to the .lst file used to auto load plugins.
358+
:parm plugin_file_path: The file path to the .lst file used to auto load C++ plugins.
346359
:type plugin_file_path: str
347360
:param alias_exe: The file path to the Alias executable.
348361
:type alias_exe: str
@@ -363,15 +376,17 @@ def __prepare_launch_args(
363376
app_args += " " + code_name_flags
364377

365378
if python_exe is None:
366-
# Launching Alias application directly - add the plugin file path to the Alias cmd
367-
# line args to auto-load the plugin.
368-
app_args += ' -P "{0}'.format(plugin_file_path)
369-
app_args += '"'
379+
# Launching Alias application directly
380+
if plugin_file_path:
381+
# Add the C++ plugin file path to the Alias cmd line args to auto-load the plugin.
382+
app_args += ' -P "{0}'.format(plugin_file_path)
383+
app_args += '"'
370384
app_path = alias_exe
371385
else:
372386
# Launching Alias indirectly to ensure the Alias Plugin uses a specific Python
373387
# version - wrap the command line to launch Alias with the given python executable
374-
app_args += f' -P \\"{plugin_file_path}\\"'
388+
if plugin_file_path:
389+
app_args += f' -P \\"{plugin_file_path}\\"'
375390
python_args = f'import os;os.system(r\'start /B \\"App\\" \\"{alias_exe}\\" {app_args}\')'
376391
app_args = f'-c "{python_args}"'
377392
app_path = python_exe

0 commit comments

Comments
 (0)