Note
Go to the end to download the full example code.
Circuit: schematic subcircuit management#
This example shows how you can use PyAEDT to add a subcircuit to a circuit design. It pushes down the child subcircuit and pops up to the parent design.
Perform required import#
Perform the required import.
import os
import pyaedt
Set AEDT version#
Set AEDT version.
aedt_version = "2024.1"
Set non-graphical mode#
Set non-graphical mode.
You can set non_graphical
either to True
or False
.
non_graphical = False
Launch AEDT with Circuit#
Launch AEDT 2023 R2 in graphical mode with Circuit.
circuit = pyaedt.Circuit(projectname=pyaedt.generate_unique_project_name(),
specified_version=aedt_version,
non_graphical=non_graphical,
new_desktop_session=True
)
circuit.modeler.schematic_units = "mil"
C:\actions-runner\_work\_tool\Python\3.10.9\x64\lib\subprocess.py:1072: ResourceWarning: subprocess 13260 is still running
_warn("subprocess %s is still running" % self.pid,
C:\actions-runner\_work\pyaedt\pyaedt\.venv\lib\site-packages\pyaedt\generic\settings.py:383: ResourceWarning: unclosed file <_io.TextIOWrapper name='D:\\Temp\\pyaedt_ansys.log' mode='a' encoding='cp1252'>
self._logger = val
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.
subcircuit = circuit.modeler.schematic.create_subcircuit(location=[0.0, 0.0])
subcircuit_name = subcircuit.composed_name
circuit.push_down(subcircuit)
True
Parametrize subcircuit#
Parametrize the subcircuit and add a resistor, inductor, and a capacitor with
the parameter values in the following code example. Connect them in series
and then use the pop_up
# method to get back to the parent design.
circuit.variable_manager.set_variable(variable_name="R_val", expression="35ohm")
circuit.variable_manager.set_variable(variable_name="L_val", expression="1e-7H")
circuit.variable_manager.set_variable(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()
True
Release AEDT#
Release AEDT.
circuit.release_desktop(True, True)
True
Total running time of the script: (0 minutes 37.941 seconds)