diff --git a/doc/source/Resources/PyAEDTInstallerFromDesktop.py b/doc/source/Resources/PyAEDTInstallerFromDesktop.py index 38e3be78795..edcafa16307 100644 --- a/doc/source/Resources/PyAEDTInstallerFromDesktop.py +++ b/doc/source/Resources/PyAEDTInstallerFromDesktop.py @@ -86,7 +86,7 @@ def run_pyinstaller_from_c_python(oDesktop): oDesktop.GetVersion()[:6], oDesktop.GetPersonalLibDirectory())) command = r'"{}" "{}"'.format(python_exe, python_script) - oDesktop.AddMessage("", "", 0, command) + oDesktop.AddMessage("", "", 0, "Configuring PyAEDT Tabs.") ret_code = os.system(command) if ret_code != 0: oDesktop.AddMessage("", "", 2, "Error configuring the configuration Tab.") @@ -97,9 +97,11 @@ def run_pyinstaller_from_c_python(oDesktop): 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." - from System.Windows.Forms import MessageBox, MessageBoxButtons, MessageBoxIcon - oDesktop.AddMessage("", "", 0, msg) - MessageBox.Show(msg, 'Info', MessageBoxButtons.OK, MessageBoxIcon.Information) + + 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) def parse_arguments_for_pyaedt_installer(args=None): @@ -175,9 +177,9 @@ def install_pyaedt(): else: run_command('"{}" -m pip install --upgrade pip'.format(python_exe)) run_command('"{}" --default-timeout=1000 install wheel'.format(pip_exe)) - run_command('"{}" --default-timeout=1000 install pyaedt[all]'.format(pip_exe)) # run_command( - # '"{}" --default-timeout=1000 install git+https://github.com/ansys/pyaedt.git@main'.format(pip_exe)) + # '"{}" --default-timeout=1000 install git+https://github.com/ansys/pyaedt.git@fix/main'.format(pip_exe)) + run_command('"{}" --default-timeout=1000 install pyaedt[all]'.format(pip_exe)) run_command('"{}" --default-timeout=1000 install jupyterlab'.format(pip_exe)) run_command('"{}" --default-timeout=1000 install ipython -U'.format(pip_exe)) run_command('"{}" --default-timeout=1000 install ipyvtklink'.format(pip_exe)) diff --git a/pyaedt/workflows/customize_automation_tab.py b/pyaedt/workflows/customize_automation_tab.py index 17e850557fe..fa8972d3844 100644 --- a/pyaedt/workflows/customize_automation_tab.py +++ b/pyaedt/workflows/customize_automation_tab.py @@ -366,6 +366,7 @@ def add_script_to_menu( build_file_data = build_file_data.replace("##IPYTHON_EXE##", ipython_executable) build_file_data = build_file_data.replace("##PYTHON_EXE##", executable_version_agnostic) build_file_data = build_file_data.replace("##JUPYTER_EXE##", jupyter_executable) + build_file_data = build_file_data.replace("##TOOLKIT_NAME##", name) if dest_script_path: build_file_data = build_file_data.replace("##PYTHON_SCRIPT##", dest_script_path) diff --git a/pyaedt/workflows/hfss3dlayout/export_to_3D.py b/pyaedt/workflows/hfss3dlayout/export_to_3D.py index 0ab251c87d7..3749cd1ec3a 100644 --- a/pyaedt/workflows/hfss3dlayout/export_to_3D.py +++ b/pyaedt/workflows/hfss3dlayout/export_to_3D.py @@ -65,7 +65,7 @@ def callback(): suffixes = {"Export to HFSS": "HFSS", "Export to Q3D": "Q3D", "Export to Maxwell 3D": "M3D", "Export to Icepak": "IPK"} if "PYAEDT_SCRIPT_PORT" in os.environ and "PYAEDT_SCRIPT_VERSION" in os.environ: - port = os.environ["PYAEDT_SCRIPT_PORT"] + port = int(os.environ["PYAEDT_SCRIPT_PORT"]) version = os.environ["PYAEDT_SCRIPT_VERSION"] else: port = 0 diff --git a/pyaedt/workflows/installer/create_report.py b/pyaedt/workflows/installer/create_report.py index 55a0ad348cd..69ee644b665 100644 --- a/pyaedt/workflows/installer/create_report.py +++ b/pyaedt/workflows/installer/create_report.py @@ -8,7 +8,7 @@ from pyaedt.generic.pdf import AnsysReport if "PYAEDT_SCRIPT_PORT" in os.environ and "PYAEDT_SCRIPT_VERSION" in os.environ: - port = os.environ["PYAEDT_SCRIPT_PORT"] + port = int(os.environ["PYAEDT_SCRIPT_PORT"]) version = os.environ["PYAEDT_SCRIPT_VERSION"] else: port = 0 diff --git a/pyaedt/workflows/installer/toolkit_manager.py b/pyaedt/workflows/installer/toolkit_manager.py index 7134172b6f7..47a08bc0a5f 100644 --- a/pyaedt/workflows/installer/toolkit_manager.py +++ b/pyaedt/workflows/installer/toolkit_manager.py @@ -34,6 +34,7 @@ from pyaedt.workflows.customize_automation_tab import add_script_to_menu from pyaedt.workflows.customize_automation_tab import available_toolkits from pyaedt.workflows.customize_automation_tab import remove_script_from_menu +import pyaedt.workflows.templates env_vars = ["PYAEDT_SCRIPT_VERSION", "PYAEDT_SCRIPT_PORT", "PYAEDT_STUDENT_VERSION"] if all(var in os.environ for var in env_vars): @@ -278,7 +279,8 @@ def button_is_clicked( else: pyaedt_venv_dir = os.path.join(os.environ["HOME"], "pyaedt_env_ide", "v{}".format(version)) executable_interpreter = os.path.join(pyaedt_venv_dir, "bin", "python") - + if not file: + file = os.path.join(os.path.dirname(pyaedt.workflows.templates.__file__), "toolkit_template.py") if os.path.isfile(executable_interpreter): add_script_to_menu( name=name, diff --git a/pyaedt/workflows/project/create_report.py b/pyaedt/workflows/project/create_report.py index 91c99945671..f6d49ded21b 100644 --- a/pyaedt/workflows/project/create_report.py +++ b/pyaedt/workflows/project/create_report.py @@ -8,7 +8,7 @@ from pyaedt.generic.pdf import AnsysReport if "PYAEDT_SCRIPT_PORT" in os.environ and "PYAEDT_SCRIPT_VERSION" in os.environ: - port = os.environ["PYAEDT_SCRIPT_PORT"] + port = int(os.environ["PYAEDT_SCRIPT_PORT"]) version = os.environ["PYAEDT_SCRIPT_VERSION"] else: port = 0 diff --git a/pyaedt/workflows/project/import_nastran.py b/pyaedt/workflows/project/import_nastran.py index 1b397e8a016..b9e9f4abebf 100644 --- a/pyaedt/workflows/project/import_nastran.py +++ b/pyaedt/workflows/project/import_nastran.py @@ -20,7 +20,7 @@ def browseFiles(): nas_input = browseFiles() if "PYAEDT_SCRIPT_PORT" in os.environ and "PYAEDT_SCRIPT_VERSION" in os.environ: - port = os.environ["PYAEDT_SCRIPT_PORT"] + port = int(os.environ["PYAEDT_SCRIPT_PORT"]) version = os.environ["PYAEDT_SCRIPT_VERSION"] else: port = 0 diff --git a/pyaedt/workflows/templates/Run_PyAEDT_Toolkit_Script.py_build b/pyaedt/workflows/templates/Run_PyAEDT_Toolkit_Script.py_build index 782db7609ab..ce406fd37e1 100644 --- a/pyaedt/workflows/templates/Run_PyAEDT_Toolkit_Script.py_build +++ b/pyaedt/workflows/templates/Run_PyAEDT_Toolkit_Script.py_build @@ -24,9 +24,6 @@ script_name = os.path.splitext(os.path.basename(__file__))[0] if is_linux: import subprocessdotnet as subprocess -else: - import subprocess - def main(): try: @@ -41,6 +38,7 @@ def main(): os.environ["PYAEDT_SCRIPT_VERSION"] = version if version > "2022.2": os.environ["PYAEDT_SCRIPT_PORT"] = str(oDesktop.GetGrpcServerPort()) + if is_linux: edt_root = os.path.normpath(oDesktop.GetExeDir()) os.environ["ANSYSEM_ROOT{}".format(version)] = edt_root @@ -53,24 +51,31 @@ def main(): ] os.environ["LD_LIBRARY_PATH"] = ":".join(ld_library_path_dirs_to_add) + ":" + os.getenv( "LD_LIBRARY_PATH", "") - command = [ - python_exe, - pyaedt_script, - str(oDesktop.GetProcessID()), - str(oDesktop.GetVersion()[:6]), - ] - my_env = os.environ.copy() + + if version > "2023.1": + os.environ["TCL_LIBRARY"] = os.path.join("{}/commonfiles/CPython/3_10/linx64/Release/python/lib".format(edt_root), "tcl8.5") + os.environ["TK_LIBRARY"] = os.path.join("{}/commonfiles/CPython/3_10/linx64/Release/python/lib".format(edt_root), "tk8.5") + os.environ["TKPATH"] = os.path.join("{}/commonfiles/CPython/3_10/linx64/Release/python/lib".format(edt_root), "tk8.5") + else: + os.environ["TCL_LIBRARY"] = os.path.join("{}/commonfiles/CPython/3_7/linx64/Release/python/lib".format(edt_root), "tcl8.5") + os.environ["TK_LIBRARY"] = os.path.join("{}/commonfiles/CPython/3_7/linx64/Release/python/lib".format(edt_root), "tk8.5") + os.environ["TKPATH"] = os.path.join("{}/commonfiles/CPython/3_7/linx64/Release/python/lib".format(edt_root), "tk8.5") + + my_env = dict(os.environ.copy()) + command = [python_exe, pyaedt_script] subprocess.Popen(command, env=my_env) else: - CREATE_NO_WINDOW = 0x08000000 - command = [ - '"{}"'.format(python_exe), - '"{}"'.format(pyaedt_script), - str(oDesktop.GetProcessID()), - str(oDesktop.GetVersion()[:6]), - ] - my_env = os.environ.copy() - subprocess.Popen(" ".join(command), env=my_env, creationflags=CREATE_NO_WINDOW) + toolkit_name = r"##TOOLKIT_NAME##" + runme = "run_pyaedt_toolkit_{0}.cmd".format(toolkit_name) + edt_temp = oDesktop.GetTempDirectory() + cmd = '"{0}"'.format(pyaedt_script) + target = os.path.join(edt_temp, runme) + my_env = dict(os.environ.copy()) + with open(target, 'w') as cmdfile: + for env in my_env: + cmdfile.write('SET {0}={1}\n'.format(env, my_env[env])) + cmdfile.write('"{0}" {1}\n'.format(python_exe, cmd)) + oDesktop.RunProgram(runme, edt_temp, edt_temp, "") except Exception as e: show_error(str(e)) diff --git a/pyaedt/workflows/templates/toolkit_template.py b/pyaedt/workflows/templates/toolkit_template.py new file mode 100644 index 00000000000..07fec8f0169 --- /dev/null +++ b/pyaedt/workflows/templates/toolkit_template.py @@ -0,0 +1,46 @@ +# Copyright (C) 2023 - 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. + +# Toolkit template if the user does not pass any valid script in the toolkit manager + +import os + +import pyaedt +from pyaedt import get_pyaedt_app + +if "PYAEDT_SCRIPT_PORT" in os.environ and "PYAEDT_SCRIPT_VERSION" in os.environ: + port = int(os.environ["PYAEDT_SCRIPT_PORT"]) + version = os.environ["PYAEDT_SCRIPT_VERSION"] +else: + port = 0 + version = "2024.1" + +app = pyaedt.Desktop(new_desktop_session=False, specified_version=version, port=port) + +active_project = app.odesktop.GetActiveProject() +active_design = active_project.GetActiveDesign() + +aedtapp = get_pyaedt_app(design_name=active_design.GetName(), desktop=app) + +# Your PyAEDT script + +app.release_desktop(False, False)