Download this example
Download this example as a Jupyter Notebook or as a Python script.
Schematic subcircuit management#
This example shows how to add a subcircuit to a circuit design. It changes the focus within the hierarchy between the child subcircuit and the parent design.
Keywords: Circuit, EMC, schematic.
Perform imports and define constants#
Perform required imports.
[1]:
import os
import tempfile
import time
[2]:
import ansys.aedt.core
Define constants.
[3]:
AEDT_VERSION = "2024.2"
NG_MODE = False # Open AEDT UI when it is launched.
Create temporary directory#
Create a temporary directory where downloaded data or dumped data can be stored. If you’d like to retrieve the project data for subsequent use, the temporary folder name is given by temp_folder.name
.
[4]:
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
Launch AEDT with Circuit#
Launch AEDT in graphical mode. Instantite an instance of the Circuit
class.
[5]:
circuit = ansys.aedt.core.Circuit(
project=os.path.join(temp_folder.name, "SubcircuitExampl.aedt"),
design="SimpleExample",
version=AEDT_VERSION,
non_graphical=NG_MODE,
new_desktop=True,
)
circuit.modeler.schematic_units = "mil"
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.12.dev0.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_ae7fbbb1-d468-4421-98fb-12903cfd771b.log is enabled.
PyAEDT INFO: Log on AEDT is enabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: New AEDT session is starting on gRPC port 60970
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
PyAEDT INFO: Ansoft.ElectronicsDesktop.2024.2 version started with process ID 7952.
PyAEDT INFO: Project SubcircuitExampl has been created.
PyAEDT INFO: Added design 'SimpleExample' of type Circuit Design.
PyAEDT INFO: Aedt Objects correctly read
PyAEDT INFO: ModelerCircuit class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: ModelerNexxim class has been initialized!
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 0sec
Add subcircuit#
Add a new subcircuit to the previously created circuit design, creating a child circuit. Push this child circuit down into the child subcircuit.
[6]:
subcircuit = circuit.modeler.schematic.create_subcircuit(location=[0.0, 0.0])
subcircuit_name = subcircuit.composed_name
circuit.push_down(subcircuit)
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.12.dev0.
PyAEDT INFO: Returning found Desktop session with PID 7952!
PyAEDT INFO: Project SubcircuitExampl set to active.
PyAEDT INFO: Aedt Objects correctly read
[6]:
True
Parametrize subcircuit#
Parametrize the subcircuit and add a resistor, inductor, and a capacitor with parameter values. Components are connected in series, and the focus is changed to the parent schematic using the pop_up()
method.
[7]:
circuit.variable_manager.set_variable(name="R_val", expression="35ohm")
circuit.variable_manager.set_variable(name="L_val", expression="1e-7H")
circuit.variable_manager.set_variable(name="C_val", expression="5e-10F")
p1 = circuit.modeler.schematic.create_interface_port(name="In")
r1 = circuit.modeler.schematic.create_resistor(value="R_val")
l1 = circuit.modeler.schematic.create_inductor(value="L_val")
c1 = circuit.modeler.schematic.create_capacitor(value="C_val")
p2 = circuit.modeler.schematic.create_interface_port(name="Out")
circuit.modeler.schematic.connect_components_in_series(
assignment=[p1, r1, l1, c1, p2], use_wire=True
)
circuit.pop_up()
PyAEDT INFO: ModelerCircuit class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: ModelerNexxim class has been initialized!
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Parsing C:/Users/ansys/AppData/Local/Temp/tmpwkgk89yf.ansys/SubcircuitExampl.aedt.
PyAEDT INFO: File C:/Users/ansys/AppData/Local/Temp/tmpwkgk89yf.ansys/SubcircuitExampl.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: aedt file load time 0.015625953674316406
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.12.dev0.
PyAEDT INFO: Returning found Desktop session with PID 7952!
PyAEDT INFO: Project SubcircuitExampl set to active.
PyAEDT INFO: Aedt Objects correctly read
[7]:
True
Release AEDT#
Release AEDT and close the example.
[8]:
circuit.save_project()
circuit.release_desktop()
# Wait 5 seconds to allow AEDT to shut down before cleaning the temporary directory.
time.sleep(5)
PyAEDT INFO: Project SubcircuitExampl Saved correctly
PyAEDT INFO: Desktop has been released and closed.
Clean up#
All project files are saved in the folder temp_folder.name
. If you’ve run this example as a Jupyter notebook, you can retrieve those project files. The following cell removes all temporary files, including the project folder.
[9]:
temp_folder.cleanup()
Download this example
Download this example as a Jupyter Notebook or as a Python script.