AEDT open project example#
This example shows how to use the AEDTCommon
class to launch a new AEDT session in a thread and open an existing AEDT project.
Perform required imports#
Perform the required imports.
[1]:
import sys
import os
import shutil
[2]:
from ansys.aedt.core import generate_unique_folder_name
[3]:
from ansys.aedt.toolkits.common.utils import download_file
from ansys.aedt.toolkits.common.backend.api import AEDTCommon
Initialize temporary folder and project settings#
Initialize a temporary folder to copy the input file into and specify project settings.
[4]:
URL_BASE = "https://raw.githubusercontent.com/ansys/example-data/master/toolkits/common/"
AEDT_PROJECT = "Test.aedt"
URL = os.path.join(URL_BASE, AEDT_PROJECT)
temp_folder = os.path.join(generate_unique_folder_name())
local_project = os.path.join(temp_folder, AEDT_PROJECT)
download_file(URL, local_project)
[4]:
'C:\\Users\\ansys\\AppData\\Local\\Temp\\pyaedt_prj_NIO\\Test.aedt'
Initialize toolkit#
Initialize the toolkit.
[5]:
toolkit = AEDTCommon()
Initialize AEDT#
Launch a new AEDT session in a thread.
[6]:
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.
[7]:
idle = toolkit.wait_to_be_idle()
if not idle:
print("AEDT not initialized.")
sys.exit()
Open project#
Open the project.
[8]:
open_msg = toolkit.open_project(local_project)
INFO - Updating internal properties.
INFO - AEDT is released.
Get toolkit properties#
Get the toolkit properties, which contain the project information.
[9]:
new_properties = toolkit.get_properties()
Connect design#
Connect or create a new design.
[10]:
toolkit.connect_design()
INFO - Updating internal properties.
INFO - Toolkit is connected to AEDT design.
[10]:
True
Create a box#
Create a box in the design.
[11]:
toolkit.logger.info("Create Box")
box = toolkit.aedtapp.modeler.create_box([10, 10, 10], [20, 20, 20])
model = toolkit.aedtapp.plot(show=True)
INFO - Create Box
Save and release AEDT#
Save and release AEDT.
[12]:
toolkit.release_aedt(True, True)
INFO - AEDT is released.
[12]:
True
Remove temporary folder#
Remove the temporary folder.
[13]:
shutil.rmtree(temp_folder, ignore_errors=True)