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

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_examples_01-Modeling-Setup_HFSS_CoordinateSystem.py>`
        to download the full example code.

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

.. _sphx_glr_examples_01-Modeling-Setup_HFSS_CoordinateSystem.py:


General: coordinate system creation
-----------------------------------
This example shows how you can use PyAEDT to create and modify coordinate systems in the modeler.

.. GENERATED FROM PYTHON SOURCE LINES 7-10

Perform required imports
~~~~~~~~~~~~~~~~~~~~~~~~
Perform required imports

.. GENERATED FROM PYTHON SOURCE LINES 10-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 in graphical mode
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Launch AEDT 2023 R2 in graphical mode.

.. GENERATED FROM PYTHON SOURCE LINES 34-37

.. code-block:: Python


    d = pyaedt.launch_desktop(specified_version=aedt_version, non_graphical=non_graphical, new_desktop_session=True)








.. GENERATED FROM PYTHON SOURCE LINES 38-41

Insert HFSS design
~~~~~~~~~~~~~~~~~~
Insert an HFSS design with the default name.

.. GENERATED FROM PYTHON SOURCE LINES 41-44

.. code-block:: Python


    hfss = pyaedt.Hfss(projectname=pyaedt.generate_unique_project_name(folder_name="CoordSysDemo"))








.. GENERATED FROM PYTHON SOURCE LINES 45-50

Create coordinate system
~~~~~~~~~~~~~~~~~~~~~~~~
The coordinate system is centered on the global origin and has the axis
aligned to the global coordinate system. The new coordinate system is
saved in the object ``cs1``.

.. GENERATED FROM PYTHON SOURCE LINES 50-53

.. code-block:: Python


    cs1 = hfss.modeler.create_coordinate_system()








.. GENERATED FROM PYTHON SOURCE LINES 54-58

Modify coordinate system
~~~~~~~~~~~~~~~~~~~~~~~~
The ``cs1`` object exposes properties and methods to manipulate the
coordinate system. The origin can be changed.

.. GENERATED FROM PYTHON SOURCE LINES 58-70

.. code-block:: Python


    cs1["OriginX"] = 10
    cs1.props["OriginY"] = 10
    cs1.props["OriginZ"] = 10

    # Pointing vectors can be changed

    ypoint = [0, -1, 0]
    cs1.props["YAxisXvec"] = ypoint[0]
    cs1.props["YAxisYvec"] = ypoint[1]
    cs1.props["YAxisZvec"] = ypoint[2]








.. GENERATED FROM PYTHON SOURCE LINES 71-74

Rename coordinate system
~~~~~~~~~~~~~~~~~~~~~~~~
Rename the coordinate system.

.. GENERATED FROM PYTHON SOURCE LINES 74-77

.. code-block:: Python


    cs1.rename("newCS")





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

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 78-83

Change coordinate system mode
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Use the ``change_cs_mode`` method to change the mode. Options are ``0``
for axis/position, ``1`` for Euler angle ZXZ, and ``2`` for Euler angle ZYZ.
Here ``1`` sets Euler angle ZXZ as the mode.

.. GENERATED FROM PYTHON SOURCE LINES 83-91

.. code-block:: Python


    cs1.change_cs_mode(1)

    # In the new mode, these properties can be edited
    cs1.props["Phi"] = "10deg"
    cs1.props["Theta"] = "22deg"
    cs1.props["Psi"] = "30deg"








.. GENERATED FROM PYTHON SOURCE LINES 92-95

Delete coordinate system
~~~~~~~~~~~~~~~~~~~~~~~~
Delete the coordinate system.

.. GENERATED FROM PYTHON SOURCE LINES 95-98

.. code-block:: Python


    cs1.delete()





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

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 99-103

Create coordinate system by defining axes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a coordinate system by defining the axes. During creation, you can
specify all coordinate system properties.

.. GENERATED FROM PYTHON SOURCE LINES 103-108

.. code-block:: Python


    cs2 = hfss.modeler.create_coordinate_system(
        name="CS2", origin=[1, 2, 3.5], mode="axis", x_pointing=[1, 0, 1], y_pointing=[0, -1, 0]
    )








.. GENERATED FROM PYTHON SOURCE LINES 109-112

Create coordinate system by defining Euler angles
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a coordinate system by defining Euler angles.

.. GENERATED FROM PYTHON SOURCE LINES 112-115

.. code-block:: Python


    cs3 = hfss.modeler.create_coordinate_system(name="CS3", origin=[2, 2, 2], mode="zyz", phi=10, theta=20, psi=30)








.. GENERATED FROM PYTHON SOURCE LINES 116-121

Create coordinate system by defining view
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a coordinate system by defining the view. Options are ``"iso"``,
``"XY"``, ``"XZ"``, and ``"XY"``. Here ``"iso"`` is specified.
The axes are set automatically.

.. GENERATED FROM PYTHON SOURCE LINES 121-124

.. code-block:: Python


    cs4 = hfss.modeler.create_coordinate_system(name="CS4", origin=[1, 0, 0], reference_cs="CS3", mode="view", view="iso")








.. GENERATED FROM PYTHON SOURCE LINES 125-130

Create coordinate system by defining axis and angle rotation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a coordinate system by defining the axis and angle rotation. When you
specify the axis and angle rotation, this data is automatically translated
to Euler angles.

.. GENERATED FROM PYTHON SOURCE LINES 130-133

.. code-block:: Python


    cs5 = hfss.modeler.create_coordinate_system(name="CS5", mode="axisrotation", u=[1, 0, 0], theta=123)








.. GENERATED FROM PYTHON SOURCE LINES 134-140

Create face coordinate system
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Face coordinate systems are bound to an object face.
First create a box and then define the face coordinate system on one of its
faces. To create the reference face for the face coordinate system, you must 
specify starting and ending points for the axis.

.. GENERATED FROM PYTHON SOURCE LINES 140-147

.. code-block:: Python


    box = hfss.modeler.create_box([0, 0, 0], [2, 2, 2])
    face = box.faces[0]
    fcs1 = hfss.modeler.create_face_coordinate_system(
        face=face, origin=face.edges[0], axis_position=face.edges[1], name="FCS1"
    )








.. GENERATED FROM PYTHON SOURCE LINES 148-152

Create face coordinate system centered on face
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a face coordinate system centered on the face with the X axis pointing
to the edge vertex.

.. GENERATED FROM PYTHON SOURCE LINES 152-157

.. code-block:: Python


    fcs2 = hfss.modeler.create_face_coordinate_system(
        face=face, origin=face, axis_position=face.edges[0].vertices[0], name="FCS2"
    )








.. GENERATED FROM PYTHON SOURCE LINES 158-162

Swap X and Y axes of face coordinate system
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Swap the X axis and Y axis of the face coordinate system. The X axis is the
pointing ``axis_position`` by default. You can optionally select the Y axis.

.. GENERATED FROM PYTHON SOURCE LINES 162-168

.. code-block:: Python


    fcs3 = hfss.modeler.create_face_coordinate_system(face=face, origin=face, axis_position=face.edges[0], axis="Y")

    # Axis can also be changed after coordinate system creation
    fcs3.props["WhichAxis"] = "X"








.. GENERATED FROM PYTHON SOURCE LINES 169-174

Apply a rotation around Z axis
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Apply a rotation around the Z axis. The Z axis of a face coordinate system
is always orthogonal to the face. A rotation can be applied at definition.
Rotation is expressed in degrees.

.. GENERATED FROM PYTHON SOURCE LINES 174-180

.. code-block:: Python


    fcs4 = hfss.modeler.create_face_coordinate_system(face=face, origin=face, axis_position=face.edges[1], rotation=10.3)

    # Rotation can also be changed after coordinate system creation
    fcs4.props["ZRotationAngle"] = "3deg"








.. GENERATED FROM PYTHON SOURCE LINES 181-185

Apply offset to X and Y axes of face coordinate system
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Apply an offset to the X axis and Y axis of a face coordinate system.
The offset is in respect to the face coordinate system itself.

.. GENERATED FROM PYTHON SOURCE LINES 185-194

.. code-block:: Python


    fcs5 = hfss.modeler.create_face_coordinate_system(
        face=face, origin=face, axis_position=face.edges[2], offset=[0.5, 0.3]
    )

    # The offset can also be changed after the coordinate system is created.
    fcs5.props["XOffset"] = "0.2mm"
    fcs5.props["YOffset"] = "0.1mm"








.. GENERATED FROM PYTHON SOURCE LINES 195-199

Create coordinate system relative to face coordinate system
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a coordinate system relative to a face coordinate system. Coordinate
systems and face coordinate systems interact with each other.

.. GENERATED FROM PYTHON SOURCE LINES 199-206

.. code-block:: Python


    face = box.faces[1]
    fcs6 = hfss.modeler.create_face_coordinate_system(face=face, origin=face, axis_position=face.edges[0])
    cs_fcs = hfss.modeler.create_coordinate_system(
        name="CS_FCS", origin=[0, 0, 0], reference_cs=fcs6.name, mode="view", view="iso"
    )








.. GENERATED FROM PYTHON SOURCE LINES 207-210

Create object coordinate system
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create object coordinate system with origin on face

.. GENERATED FROM PYTHON SOURCE LINES 210-215

.. code-block:: Python


    obj_cs = hfss.modeler.create_object_coordinate_system(assignment=box, origin=box.faces[0], x_axis=box.edges[0],
                                                          y_axis=[0, 0, 0], name="box_obj_cs")
    obj_cs.rename("new_obj_cs")





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

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 216-219

Create object coordinate system
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create object coordinate system with origin on edge

.. GENERATED FROM PYTHON SOURCE LINES 219-224

.. code-block:: Python


    obj_cs_1 = hfss.modeler.create_object_coordinate_system(assignment=box.name, origin=box.edges[0], x_axis=[1, 0, 0],
                                                            y_axis=[0, 1, 0], name="obj_cs_1")
    obj_cs_1.set_as_working_cs()





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

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 225-228

Create object coordinate system
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create object coordinate system with origin specified on point

.. GENERATED FROM PYTHON SOURCE LINES 228-234

.. code-block:: Python


    obj_cs_2 = hfss.modeler.create_object_coordinate_system(assignment=box.name, origin=[0, 0.8, 0], x_axis=[1, 0, 0],
                                                            y_axis=[0, 1, 0], name="obj_cs_2")
    new_obj_cs_2 = hfss.modeler.duplicate_coordinate_system_to_global(obj_cs_2)
    obj_cs_2.delete()





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

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 235-238

Create object coordinate system
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create object coordinate system with origin on vertex

.. GENERATED FROM PYTHON SOURCE LINES 238-244

.. code-block:: Python


    obj_cs_3 = hfss.modeler.create_object_coordinate_system(assignment=box.name, origin=box.vertices[1],
                                                            x_axis=box.faces[2], y_axis=box.faces[4], name="obj_cs_3")
    obj_cs_3.props["MoveToEnd"] = False
    obj_cs_3.update()





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

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 245-248

Get all coordinate systems
~~~~~~~~~~~~~~~~~~~~~~~~~~
Get all coordinate systems.

.. GENERATED FROM PYTHON SOURCE LINES 248-253

.. code-block:: Python


    css = hfss.modeler.coordinate_systems
    names = [i.name for i in css]
    print(names)





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

 .. code-block:: none

    ['obj_cs_3', 'obj_cs_1', 'new_obj_cs', 'CS_FCS', 'Face_CS_7BI4J6', 'Face_CS_XTJ2RC', 'Face_CS_XEBDPP', 'Face_CS_V81D43', 'FCS2', 'FCS1', 'CS5', 'CS4', 'CS3', 'CS2']




.. GENERATED FROM PYTHON SOURCE LINES 254-257

Select coordinate system
~~~~~~~~~~~~~~~~~~~~~~~~
Select an existing coordinate system.

.. GENERATED FROM PYTHON SOURCE LINES 257-262

.. code-block:: Python


    css = hfss.modeler.coordinate_systems
    cs_selected = css[0]
    cs_selected.delete()





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

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 263-267

Get point coordinate under another coordinate system
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get a point coordinate under another coordinate system. A point coordinate
can be translated in respect to any coordinate system.

.. GENERATED FROM PYTHON SOURCE LINES 267-274

.. code-block:: Python


    hfss.modeler.create_box([-10, -10, -10], [20, 20, 20], "Box1")
    p = hfss.modeler["Box1"].faces[0].vertices[0].position
    print("Global: ", p)
    p2 = hfss.modeler.global_to_cs(p, "CS5")
    print("CS5 :", p2)





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

 .. code-block:: none

    Global:  [-10.0, -10.0, 10.0]
    CS5 : [-10.0, 13.8330960296045, 2.940315329304]




.. GENERATED FROM PYTHON SOURCE LINES 275-280

Close AEDT
~~~~~~~~~~
After the simulaton completes, you can close AEDT or release it using the
:func:`pyaedt.Desktop.release_desktop` method.
All methods provide for saving the project before closing.

.. GENERATED FROM PYTHON SOURCE LINES 280-282

.. code-block:: Python


    d.release_desktop()




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

 .. code-block:: none


    True




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

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


.. _sphx_glr_download_examples_01-Modeling-Setup_HFSS_CoordinateSystem.py:

.. only:: html

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

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

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

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

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


.. only:: html

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

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