Skip to content

Commit

Permalink
Add workflows as simple scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys committed May 3, 2024
1 parent b16a6d0 commit 563bc82
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 19 deletions.
57 changes: 40 additions & 17 deletions pyaedt/workflows/hfss3dlayout/export_to_3D.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,68 @@
import os
from tkinter import Button
from tkinter import Entry
from tkinter import Label
from tkinter import RAISED
from tkinter import StringVar
from tkinter import Tk
from tkinter import mainloop
from tkinter import ttk
from tkinter.ttk import Combobox

import PIL.Image
import PIL.ImageTk

from pyaedt import Desktop
from pyaedt import Hfss
from pyaedt import Hfss3dLayout
from pyaedt import Icepak
from pyaedt import Maxwell3d
from pyaedt import Q3d
import pyaedt.workflows.hfss3dlayout

master = Tk()

master.geometry("400x150")

master.title("Export to 3D")

# Load the logo for the main window
icon_path = os.path.join(os.path.dirname(pyaedt.workflows.__file__), "images", "large", "logo.png")
im = PIL.Image.open(icon_path)
photo = PIL.ImageTk.PhotoImage(im)

# Set the icon for the main window
master.iconphoto(True, photo)

# Configure style for ttk buttons
style = ttk.Style()
style.configure("Toolbutton.TButton", padding=6, font=("Helvetica", 10))

var = StringVar()
label = Label(master, textvariable=var, relief=RAISED)
var.set("1 - Export to HFSS\n2 - Export to Q3D\n3 - Export to Maxwell 3D\n4 - Export to Icepak")
label.pack()
e = Entry(master)
e.pack()
var.set("Choose an option:")
label.pack(pady=10)
combo = Combobox(master, width=40) # Set the width of the combobox
combo["values"] = ("Export to HFSS", "Export to Q3D", "Export to Maxwell 3D", "Export to Icepak")
combo.current(0)
combo.pack(pady=10)

e.focus_set()
choice = "1"
combo.focus_set()
choice = "Export to HFSS"


def callback():
global choice
choice = e.get() # This is the text you may want to use later
choice = combo.get()
master.destroy()
return True


b = Button(master, text="OK", width=10, command=callback)
b.pack()
b = Button(master, text="Export", width=40, command=callback)
b.pack(pady=10)

mainloop()
if choice not in ["1", "2", "3", "4"]:
raise Exception("Wrong input.")
suffixes = {"1": "HFSS", "2": "Q3D", "3": "M3D", "4": "IPK"}

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"]
Expand All @@ -62,19 +85,19 @@ def callback():
setup = h3d.create_setup()
suffix = suffixes[choice]

if choice == "2":
if choice == "Export to Q3D":
setup.export_to_q3d(h3d.project_file[:-5] + f"_{suffix}.aedt", keep_net_name=True)
else:
setup.export_to_hfss(h3d.project_file[:-5] + f"_{suffix}.aedt", keep_net_name=True)
h3d.delete_setup(setup.name)
if choice == "2":
if choice == "Export to Q3D":
app = Q3d(projectname=h3d.project_file[:-5] + f"_{suffix}.aedt")
else:
app = Hfss(projectname=h3d.project_file[:-5] + f"_{suffix}.aedt")
app2 = None
if choice == "3":
if choice == "Export to Maxwell 3D":
app2 = Maxwell3d(projectname=app.project_name)
elif choice == "4":
elif choice == "Export to Icepak":
app2 = Icepak(projectname=app.project_name)
if app2:
app2.copy_solid_bodies_from(
Expand Down
File renamed without changes
4 changes: 2 additions & 2 deletions pyaedt/workflows/installer/toolkit_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@

from pyaedt import Desktop
from pyaedt import is_windows
import pyaedt.workflows
from pyaedt.workflows.customize_automation_tab import add_custom_toolkit
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.installer

env_vars = ["PYAEDT_SCRIPT_VERSION", "PYAEDT_SCRIPT_PORT", "PYAEDT_STUDENT_VERSION"]
if all(var in os.environ for var in env_vars):
Expand Down Expand Up @@ -292,7 +292,7 @@ def button_is_clicked(
root.title("AEDT Toolkit Manager")

# Load the logo for the main window
icon_path = os.path.join(os.path.dirname(pyaedt.workflows.installer.__file__), "images", "large", "logo.png")
icon_path = os.path.join(os.path.dirname(pyaedt.workflows.__file__), "images", "large", "logo.png")
im = PIL.Image.open(icon_path)
photo = PIL.ImageTk.PhotoImage(im)

Expand Down
39 changes: 39 additions & 0 deletions pyaedt/workflows/project/create_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generate pdf report
# ~~~~~~~~~~~~~~~~~~~
# Generate a pdf report with output of simulation.
import os

from pyaedt import Desktop
from pyaedt import get_pyaedt_app
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"]
version = os.environ["PYAEDT_SCRIPT_VERSION"]
else:
port = 0
version = "2024.1"

with Desktop(new_desktop_session=False, close_on_exit=False, specified_version=version, port=port) as d:

proj = d.active_project()
des = d.active_design()
projname = proj.GetName()
desname = des.GetName()
if des.GetDesignType() in ["HFSS 3D Layout Design", "Circuit Design"]:
desname = None
app = get_pyaedt_app(projname, desname)

report = AnsysReport(version=d.aedt_version_id, design_name=app.design_name, project_name=app.project_name)
report.create()
report.add_section()
report.add_chapter(f"{app.solution_type} Results")
report.add_sub_chapter("Plots")
report.add_text("This section contains all reports results.")
for plot in app.post.plots:
app.post.export_report_to_jpg(app.working_directory, plot.plot_name)
report.add_image(os.path.join(app.working_directory, plot.plot_name + ".jpg"), plot.plot_name)
report.add_page_break()
report.add_toc()
out = report.save_pdf(app.working_directory, "AEDT_Results.pdf")
d.odesktop.AddMessage("", "", 0, f"Report Generated. {out}")
Binary file added pyaedt/workflows/project/images/large/pdf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions pyaedt/workflows/project/toolkits_catalog.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[GenerateReport]
name = "Generate report"
script = "create_report.py"
icon = "images/large/pdf.png"
template = "Run_PyAEDT_Script"
pip = ""

0 comments on commit 563bc82

Please sign in to comment.