.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples\07-Circuit\Circuit_Subcircuit_Example.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_examples_07-Circuit_Circuit_Subcircuit_Example.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_07-Circuit_Circuit_Subcircuit_Example.py:


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.

.. GENERATED FROM PYTHON SOURCE LINES 8-11

Perform required import
~~~~~~~~~~~~~~~~~~~~~~~
Perform the required import.

.. GENERATED FROM PYTHON SOURCE LINES 11-15

.. code-block:: Python


    import os
    import pyaedt








.. GENERATED FROM PYTHON SOURCE LINES 16-19

Set AEDT version
~~~~~~~~~~~~~~~~
Set AEDT version.

.. GENERATED FROM PYTHON SOURCE LINES 19-22

.. code-block:: Python


    aedt_version = "2024.1"








.. GENERATED FROM PYTHON SOURCE LINES 23-27

Set non-graphical mode
~~~~~~~~~~~~~~~~~~~~~~
Set non-graphical mode. 
You can set ``non_graphical`` either to ``True`` or ``False``.

.. GENERATED FROM PYTHON SOURCE LINES 27-30

.. code-block:: Python


    non_graphical = False








.. GENERATED FROM PYTHON SOURCE LINES 31-34

Launch AEDT with Circuit
~~~~~~~~~~~~~~~~~~~~~~~~
Launch AEDT 2023 R2 in graphical mode with Circuit.

.. GENERATED FROM PYTHON SOURCE LINES 34-42

.. code-block:: Python


    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"





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    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




.. GENERATED FROM PYTHON SOURCE LINES 43-47

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.

.. GENERATED FROM PYTHON SOURCE LINES 47-52

.. code-block:: Python


    subcircuit = circuit.modeler.schematic.create_subcircuit(location=[0.0, 0.0])
    subcircuit_name = subcircuit.composed_name
    circuit.push_down(subcircuit)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 53-58

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.

.. GENERATED FROM PYTHON SOURCE LINES 58-71

.. code-block:: Python


    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()






.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 72-75

Release AEDT
~~~~~~~~~~~~
Release AEDT.

.. GENERATED FROM PYTHON SOURCE LINES 75-77

.. code-block:: Python


    circuit.release_desktop(True, True)




.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    True




.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 37.941 seconds)


.. _sphx_glr_download_examples_07-Circuit_Circuit_Subcircuit_Example.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: Circuit_Subcircuit_Example.ipynb <Circuit_Subcircuit_Example.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: Circuit_Subcircuit_Example.py <Circuit_Subcircuit_Example.py>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_