Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Icepak ECAD import example with Ansys board #221

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
145 changes: 82 additions & 63 deletions examples/05-electrothermal/ecad_import.py
Original file line number Diff line number Diff line change
@@ -1,114 +1,133 @@
# # Importing a PCB and its components via IDF and EDB
# # Import an ECAD into Icepak and modify stackup properties

# This example shows how to import a PCB and its components using IDF files (*.ldb/*.bdf).
# The *.emn/*.emp combination can also be used in a similar way.
# This example shows how to import an ECAD as a PCB component into Icepak.
# It will also demonstrate how to change the materials of the PCB layers and
# update the PCB in Icepak.
#
# Keywords: **Icepak**, **PCB**, **IDF**.
# Keywords: **Icepak**, **PCB**

# ## Perform required imports
#
# Perform required imports including the operating system, Ansys PyAEDT packages.

import os
import tempfile
import time
import tempfile

import ansys.aedt.core
from ansys.aedt.core import Hfss3dLayout, Icepak
from ansys.aedt.core import Edb
from ansys.aedt.core import Hfss3dLayout, Icepak, downloads
ansys-satyajeet marked this conversation as resolved.
Show resolved Hide resolved

# ## Define constants

AEDT_VERSION = "2024.2"
NG_MODE = False # Open Electronics UI when the application is launched.

NG_MODE = False # Open AEDT interface when False
#
# ## Open project
#
# Open an empty project in non-graphical mode, using a temporary folder.
# Open an empty project in graphical mode, using a temporary folder.

# +
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
project_name = "Icepak_ECAD_Import"
ansys-satyajeet marked this conversation as resolved.
Show resolved Hide resolved
project_path = os.path.join(temp_folder.name, f"{project_name}.aedt")

# Add an Icepak design
ipk = Icepak(
project=os.path.join(temp_folder.name, "Icepak_ECAD_Import.aedt"),
project=project_name,
version=AEDT_VERSION,
new_desktop=True,
non_graphical=NG_MODE,
)
# -

# ## Import the IDF files
#
# Sample *.bdf and *.ldf files are presented here.
#
# <img src="_static\bdf.png" width="400">
#
# <img src="_static\ldf.png" width="400">
#
# Imports the idf files with several filtering options including caps, resistors,
# inductors, power, specific power, size...
# There are also options for the PCB creation (number o flayers, copper percentages, layer sizes).
# In this example, the default values are used for the PCB.
# The imported PCB (from IDF) here will be deleted later and replaced by a PCB that has the trace
# information (from ECAD) for higher accuracy.
# Disable autosave
ipk.autosave_disable()

# Save Icepak project
ipk.save_project()
# -

# Download ECAD and IDF files
# Download the ECAD file

def_path = ansys.aedt.core.downloads.download_file(
source="icepak/Icepak_ECAD_Import/A1_uprev.aedb",
ecad_path = downloads.download_file(
source="edb/ANSYS-HSD_V1.aedb",
name="edb.def",
destination=temp_folder.name,
)
board_path = ansys.aedt.core.downloads.download_file(
source="icepak/Icepak_ECAD_Import/", name="A1.bdf", destination=temp_folder.name

# ## Import ECAD
# Add an HFSS 3D Layout design with the layout information of the PCB
h3d_design_name = "PCB_TEMP"
h3d = Hfss3dLayout(
project=project_name,
design=h3d_design_name,
version=AEDT_VERSION,
)
library_path = ansys.aedt.core.downloads.download_file(
source="icepak/Icepak_ECAD_Import/", name="A1.ldf", destination=temp_folder.name
h3d.import_edb(ecad_path)
h3d.save_project()

# Delete the empty placeholder HFSS 3D layout design
ipk.delete_design(name=h3d_design_name, fallback_design=None)

# Set component name and ECAD source name and ECAD project path to be linked to Icepak
component_name = "PCB_ECAD"
layout_name = h3d.design_name
ecad_source = os.path.join(h3d.project_path, f"{h3d.project_name}.aedt")

# Create a PCB component in Icepak linked to the 3D Layout project.
# Polygon ``"poly_5949"`` is used as the outline of the PCB and
# a dissipation of ``"1W"`` is applied to the PCB.

# Create PCB component in Icepak
pcb_comp = ipk.create_pcb_from_3dlayout(
component_name=component_name,
project_name=ecad_source,
design_name=layout_name,
resolution=3,
extent_type="Polygon",
outline_polygon="poly_5949",
power_in=1,
)

# Import IDF

ipk.import_idf(board_path=board_path)

# Save the project

# Save project
ipk.save_project()

# ## Import ECAD
# Add an HFSS 3D Layout design with the layout information of the PCB
# Initialize PyEDB object to modify ECAD
edb = Edb(edbpath=ecad_path, edbversion=AEDT_VERSION)

hfss3d_lo = Hfss3dLayout(project=def_path, version=AEDT_VERSION)
hfss3d_lo.save_project()
# Change dielectric fill in signal layers
for name, layer in edb.stackup.signal_layers.items():
layer.dielectric_fill = "FR4_epoxy"

# Create a PCB component in Icepak linked to the 3D Layout project. The polygon ``"poly_0"``
# is used as the outline of the PCB and a dissipation of ``"1W"`` is applied to the PCB.
# Change material of dielectric layers
for name, layer in edb.stackup.dielectric_layers.items():
layer.material = "FR4_epoxy"

ipk.create_pcb_from_3dlayout(
component_name="PCB_pyAEDT",
project_name=hfss3d_lo.project_file,
design_name=hfss3d_lo.design_name,
extenttype="Polygon",
outlinepolygon="poly_0",
power_in=1,
)
# Save EDB
edb.save_edb()

# Delete the simplified PCB object coming from IDF import.
# Close edb session
edb.close_edb()

ipk.modeler["IDF_BoardOutline"].delete()
# Update layers of PCB with new materials in PCB component
pcb_comp.update()

# ## Plot model
# Change properties of PCB component such as board cutout material and via fill material
pcb_comp.board_cutout_material = "FR4_epoxy"
pcb_comp.via_holes_material = "FR4_epoxy"

ipk.plot(
show=False,
export_path=os.path.join(temp_folder.name, "ECAD_import.jpg"),
plot_air_objects=False,
force_opacity_value=1,
)
# Modify the power specified on PCB
pcb_comp.power = "2W"

# ## Release AEDT
# Print path of the linked ECAD source defintion
print(pcb_comp.native_properties["DefnLink"]["Project"])

# Save project and release desktop
ipk.save_project()
ipk.release_desktop()
# Wait 3 seconds to allow Electronics Desktop to shut down before cleaning the temporary directory.

# Wait 3 seconds to allow Electronics Desktop to shut down
# before cleaning the temporary directory.
time.sleep(3)

# ## Cleanup
Expand Down
Loading