Skip to content

Commit

Permalink
New AEDT example
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys committed Feb 16, 2024
1 parent 2de6945 commit b428fd3
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 101 deletions.
94 changes: 94 additions & 0 deletions doc/source/examples/aedt_common/api_aedt_connect_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# # AEDT connect session example
#
# This example shows how to use the Common AEDT API to
# connect to an existing AEDT session,
# create a HFSS design and create a waveguide.

# ## Perform required imports
#
# Perform required imports.

import sys
from ansys.aedt.toolkits.common.backend.api import AEDTCommon
import pyaedt


# ## Initialize toolkit
#
# Initialize the toolkit.

toolkit = AEDTCommon()

# ## Get toolkit properties
#
# Get the toolkit properties.

properties_from_backend = toolkit.get_properties()

# ## Initialize AEDT
#
# Initialize AEDT using PyAEDT and release it.
pyaedt.settings.enable_logger = False
app = pyaedt.Desktop(specified_version=properties_from_backend["aedt_version"],
non_graphical=properties_from_backend["non_graphical"])
app.release_desktop(close_projects=False, close_on_exit=False)

# ## Get AEDT sessions
#
# Get AEDT sessions and select the first one.

sessions = toolkit.aedt_sessions()
first_key, first_value = next(iter(sessions.items()))
if first_value == -1:
use_grpc = False
selected_process = first_key
else:
use_grpc = True
selected_process = first_value

# ## Set properties
#
# AEDT session selection.

new_properties = {"selected_process": selected_process, "use_grpc": use_grpc}
flag, msg = toolkit.set_properties(new_properties)

# ## Initialize AEDT
#
# Launch a new AEDT session in a thread.

thread_msg = toolkit.launch_thread(toolkit.launch_aedt)

# ## Wait for the toolkit thread to be idle
#
# Wait for the toolkit thread to be idle and ready to accept a new task.

idle = toolkit.wait_to_be_idle()
if not idle:
print("AEDT not initialized.")
sys.exit()

# ## Connect design
#
# Connect or create a new design.

toolkit.connect_design("HFSS")

# ## Get toolkit properties
#
# Properties contain the project information.

new_properties = toolkit.get_properties()

# ## Create a waveguide
#
# Create a waveguide in the design.

wg = toolkit.aedtapp.modeler.create_waveguide([0, 0, 0], 1)
toolkit.aedtapp.plot()

# ## Save and release AEDT
#
# Save and release AEDT.

toolkit.release_aedt(True, True)
7 changes: 6 additions & 1 deletion doc/source/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Common AEDT API examples.

aedt_common/api_aedt_simple.py
aedt_common/api_aedt_open_project.py
aedt_common/api_aedt_connect_session.py

Common EDB API
~~~~~~~~~~~~~~
Expand All @@ -25,4 +26,8 @@ Common API examples.

.. nbgallery::

properties_common/api_properties.py
properties_common/api_properties.py

REST API

Check warning on line 31 in doc/source/examples/index.rst

View workflow job for this annotation

GitHub Actions / vale

[vale] doc/source/examples/index.rst#L31

[Google.Headings] 'REST API' should use sentence-style capitalization.
Raw output
{"message": "[Google.Headings] 'REST API' should use sentence-style capitalization.", "location": {"path": "doc/source/examples/index.rst", "range": {"start": {"line": 31, "column": 1}}}, "severity": "WARNING"}
~~~~~~~~
Find here a `REST API example <https://github.com/ansys-internal/pyaedt-toolkits-common>`_.
1 change: 1 addition & 0 deletions doc/styles/Vocab/ANSYS/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Rest_api.py
Properties.json
Api.py
EDBCommon
EDB API
54 changes: 0 additions & 54 deletions examples/backend/api_aedt_connect_session_example.py

This file was deleted.

6 changes: 0 additions & 6 deletions examples/backend/backend_properties.json

This file was deleted.

40 changes: 0 additions & 40 deletions examples/backend/models.py

This file was deleted.

0 comments on commit b428fd3

Please sign in to comment.