diff --git a/src/ansys/edb/core/inner/ui_manager.py b/src/ansys/edb/core/inner/ui_manager.py new file mode 100644 index 0000000000..6fb6dd4d90 --- /dev/null +++ b/src/ansys/edb/core/inner/ui_manager.py @@ -0,0 +1,17 @@ +"""UI Manager.""" + +from ansys.api.edb.v1 import ui_manager_pb2_grpc +import google.protobuf.empty_pb2 as empty_pb2 + +from ansys.edb.core.session import StubAccessor, StubType + + +class UIManager: + """Provides access to the UI Manager service.""" + + __stub: ui_manager_pb2_grpc.UIManagerServiceStub = StubAccessor(StubType.ui_manager) + + @classmethod + def sync_3d_layout_ui(cls): + """Synchronize the 3D layout UI.""" + cls.__stub.Sync3DLayoutUI(empty_pb2.Empty()) diff --git a/src/ansys/edb/core/session.py b/src/ansys/edb/core/session.py index f78e1bee97..344c4cc72e 100644 --- a/src/ansys/edb/core/session.py +++ b/src/ansys/edb/core/session.py @@ -158,6 +158,7 @@ from ansys.api.edb.v1.text_pb2_grpc import TextServiceStub from ansys.api.edb.v1.transform_3d_pb2_grpc import Transform3DServiceStub from ansys.api.edb.v1.transform_pb2_grpc import TransformServiceStub +from ansys.api.edb.v1.ui_manager_pb2_grpc import UIManagerServiceStub from ansys.api.edb.v1.value_pb2_grpc import ValueServiceStub from ansys.api.edb.v1.variable_server_pb2_grpc import VariableServerServiceStub from ansys.api.edb.v1.via_group_pb2_grpc import ViaGroupServiceStub @@ -476,6 +477,7 @@ class StubType(Enum): q3d_dcrl_sim_settings = Q3DDCRLSettingsServiceStub q3d_general_sim_settings = Q3DGeneralSettingsServiceStub q3d_sim_settings = Q3DSettingsServiceStub + ui_manager = UIManagerServiceStub def attach_session( @@ -576,6 +578,39 @@ def session( MOD.current_session.disconnect() +@contextmanager +def aedt_session(ip_address: str, port_num: int): + r"""Attach to an existing AEDT session in a context manager. + + Parameters + ---------- + ip_address : str + IP address of the machine that is running the server. + port_num : int + Port number that the server is listening on. + + Examples + -------- + Attach to an existing AEDT session that automatically synchronizes the 3D layout UI + and disconnects when it goes out of scope. + + >>> with aedt_session("localhost", 50051) as session: + >>> # program goes here + """ + try: + attach_session(ip_address, port_num) + yield + from ansys.edb.core.inner.ui_manager import UIManager + + UIManager.sync_3d_layout_ui() + except EDBSessionException: + raise + except Exception as e: # noqa + raise + finally: + MOD.current_session.disconnect() + + def get_layer_collection_stub() -> LayerCollectionServiceStub: """Get the layer collection stub.