diff --git a/doc/source/Getting_started/Installation.rst b/doc/source/Getting_started/Installation.rst index 50a0f2bba10..ff37cae9cc9 100644 --- a/doc/source/Getting_started/Installation.rst +++ b/doc/source/Getting_started/Installation.rst @@ -110,6 +110,15 @@ Finally, in the python console, run the following commands: from ansys.aedt.core.workflows.installer.pyaedt_installer import add_pyaedt_to_aedt add_pyaedt_to_aedt(“your_aedt_version", r“path_to_personalib") +You can also install the PyAEDT panels using the following steps, this is also useful if you have a centralized PyAEDT installation: + +- Download the following file: :download:`PyAEDT panel Installer Python file <../Resources/toolkit_installer_from_aedt.py>` + +- Define an environment variable called `PYAEDT_INTERPRETER` with the path of the python interpreter in which PyAEDT is installed. + +- Open an Electronics Desktop Session and click on Tools->Run Script and execute the file. You do not need the previous step if +you pass as an argument the path of the python interpreter. + Linux support ~~~~~~~~~~~~~ diff --git a/doc/source/Resources/toolkit_installer_from_aedt.py b/doc/source/Resources/toolkit_installer_from_aedt.py new file mode 100644 index 00000000000..017f08ee70b --- /dev/null +++ b/doc/source/Resources/toolkit_installer_from_aedt.py @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021 - 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import os +import sys +import subprocessdotnet as subprocess + +# This script installs PyAEDT tabs (PyAEDT Console, Jupyter, Run Script and Extension Manager) +# using a specific Python interpreter. +# It can be passed from an environment variable called "PYAEDT_INTERPRETER" or from the input argument. +# The environment variable has more priority. + +is_linux = os.name == "posix" +is_windows = not is_linux + +pyaedt_enviroment_variable = "PYAEDT_INTERPRETER" + + +def run_pyinstaller_from_c_python(oDesktop, pyaedt_interpreter): + # Iron Python script to create PyAEDT panels + + # Get AEDT information + version = oDesktop.GetVersion()[2:6].replace(".", "") + + # Add PyAEDT tabs in AEDT + + # Create Toolkits in PersonalLib + import tempfile + python_script = os.path.join(tempfile.gettempdir(), "configure_pyaedt.py") + if os.path.isfile(python_script): + os.remove(python_script) + with open(python_script, "w") as f: + f.write("from ansys.aedt.core.workflows.installer.pyaedt_installer import add_pyaedt_to_aedt\n") + f.write( + 'add_pyaedt_to_aedt(aedt_version="{}", personal_lib=r"{}")\n'.format( + oDesktop.GetVersion()[:6], oDesktop.GetPersonalLibDirectory())) + + command = [pyaedt_interpreter, python_script] + oDesktop.AddMessage("", "", 0, "Configuring PyAEDT panels in automation tab.") + process = subprocess.Popen(command) + process.wait() + + # Refresh UI + oDesktop.CloseAllWindows() + if version >= "232": + oDesktop.RefreshToolkitUI() + msg = "PyAEDT configuration complete." + if is_linux: + msg += " Please ensure Ansys Electronics Desktop is launched in gRPC mode (i.e. launch ansysedt with -grpcsrv" \ + " argument) to take advantage of the new toolkits." + + if "GetIsNonGraphical" in oDesktop.__dir__() and not oDesktop.GetIsNonGraphical(): + from System.Windows.Forms import MessageBox, MessageBoxButtons, MessageBoxIcon + oDesktop.AddMessage("", "", 0, msg) + MessageBox.Show(msg, 'Info', MessageBoxButtons.OK, MessageBoxIcon.Information) + oDesktop.AddMessage("", "", 0, "Create a project if the PyAEDT panel is not visible.") + + +if __name__ == "__main__": + + python_interpreter = os.getenv(pyaedt_enviroment_variable) + if python_interpreter and not os.path.exists(python_interpreter): + oDesktop.AddMessage("", "", 2, "Python environment does not exist.") + sys.exit() + + # Check if interpreter path is defined. + # Retrieve the script arguments + script_args = ScriptArgument.split() + if len(script_args) == 1 and not python_interpreter: + python_interpreter = script_args[0] + if not os.path.exists(python_interpreter): + oDesktop.AddMessage("", "", 2, "Python environment does not exist.") + sys.exit() + + if not python_interpreter: + oDesktop.AddMessage("", "", 2, "Invalid python environment.") + sys.exit() + + run_pyinstaller_from_c_python(oDesktop, python_interpreter) diff --git a/src/ansys/aedt/core/workflows/installer/extension_manager.py b/src/ansys/aedt/core/workflows/installer/extension_manager.py index fbc5a61ddde..1c2265549a5 100644 --- a/src/ansys/aedt/core/workflows/installer/extension_manager.py +++ b/src/ansys/aedt/core/workflows/installer/extension_manager.py @@ -22,6 +22,7 @@ # SOFTWARE. import os +import sys import tkinter as tk from tkinter import ttk @@ -54,13 +55,10 @@ venv_dir = os.path.join(os.environ["APPDATA"], VENV_DIR_PREFIX, f"toolkits_{python_version.replace('.', '_')}") python_exe = os.path.join(venv_dir, "Scripts", "python.exe") package_dir = os.path.join(venv_dir, "Lib", "site-packages") - pyaedt_venv_dir = os.path.join(os.environ["APPDATA"], VENV_DIR_PREFIX, f"{python_version.replace('.', '_')}") - else: venv_dir = os.path.join(os.environ["HOME"], VENV_DIR_PREFIX, f"toolkits_{python_version.replace('.', '_')}") python_exe = os.path.join(venv_dir, "bin", "python") package_dir = os.path.join(venv_dir, "lib", "site-packages") - pyaedt_venv_dir = os.path.join(os.environ["HOME"], VENV_DIR_PREFIX, f"{python_version.replace('.', '_')}") def create_toolkit_page(frame, window_name, internal_toolkits): @@ -281,11 +279,10 @@ def button_is_clicked( else: if install_action: - desktop.logger.info(f"Install {name}") - if is_windows: - executable_interpreter = os.path.join(pyaedt_venv_dir, "Scripts", "python.exe") - else: - executable_interpreter = os.path.join(pyaedt_venv_dir, "bin", "python") + desktop.logger.info("Install {}".format(name)) + + executable_interpreter = sys.executable + if not file: file = os.path.join( os.path.dirname(ansys.aedt.core.workflows.templates.__file__), "extension_template.py"