@@ -75,6 +75,7 @@ def launch_modeler(mode: str = None, **kwargs: dict | None) -> "Modeler":
7575 * For ``"docker"`` mode, see the :func:`launch_docker_modeler` method.
7676 * For ``"geometry_service"`` mode, see the
7777 :func:`launch_modeler_with_geometry_service` method.
78+ * For ``"core_service"`` mode, see the :func:`launch_modeler_with_core_service` method.
7879 * For ``"spaceclaim"`` mode, see the :func:`launch_modeler_with_spaceclaim` method.
7980 * For ``"discovery"`` mode, see the :func:`launch_modeler_with_discovery` method.
8081
@@ -108,6 +109,8 @@ def _launch_with_launchmode(mode: str, **kwargs: dict | None) -> "Modeler":
108109 * ``"docker"``: Launches the ``Modeler`` service locally using Docker.
109110 * ``"geometry_service"``: Launches the ``Modeler`` service locally using the
110111 Ansys Geometry Service.
112+ * ``"core_service"``: Launches the ``Modeler`` service locally using the
113+ Ansys Geometry Core Service.
111114 * ``"spaceclaim"``: Launches the ``Modeler`` service locally using Ansys SpaceClaim.
112115 * ``"discovery"``: Launches the ``Modeler`` service locally using Ansys Discovery.
113116
@@ -132,6 +135,8 @@ def _launch_with_launchmode(mode: str, **kwargs: dict | None) -> "Modeler":
132135 return launch_remote_modeler (** kwargs )
133136 elif mode == "docker" :
134137 return launch_docker_modeler (** kwargs )
138+ elif mode == "core_service" :
139+ return launch_modeler_with_core_service (** kwargs )
135140 elif mode == "geometry_service" :
136141 return launch_modeler_with_geometry_service (** kwargs )
137142 elif mode == "spaceclaim" :
@@ -167,8 +172,9 @@ def _launch_with_automatic_detection(**kwargs: dict | None) -> "Modeler":
167172 #
168173 # 1. Check if PyPIM is configured and if the environment is configured for it.
169174 # 2. Check if Docker is installed and if the environment is configured for it.
170- # 3. If you are on a Windows machine:
171- # - check if the Ansys Geometry service is installed.
175+ # 3. Check if the Ansys Geometry Core service is installed. (OS agnostic)
176+ # 4. If you are on a Windows machine:
177+ # - check if the Ansys Geometry DMS service is installed.
172178 # - check if Ansys SpaceClaim is installed.
173179 # - check if Ansys Discovery is installed.
174180
@@ -189,15 +195,23 @@ def _launch_with_automatic_detection(**kwargs: dict | None) -> "Modeler":
189195 " Trying to start the Geometry service locally."
190196 )
191197
198+ try :
199+ LOG .info ("Starting Geometry Core service locally." )
200+ return launch_modeler_with_core_service (** kwargs )
201+ except Exception :
202+ wrn_msg = "The Geometry Core service could not be started locally."
203+ wrn_msg += " Trying to start the Geometry DMS service locally." if os .name == "nt" else ""
204+ LOG .warning (wrn_msg )
205+
192206 # If we are on a Windows machine, we can try to start the Geometry service locally,
193207 # through various methods: Geometry service, SpaceClaim, Discovery.
194208 if os .name == "nt" :
195209 try :
196- LOG .info ("Starting Geometry service locally." )
210+ LOG .info ("Starting Geometry DMS service locally." )
197211 return launch_modeler_with_geometry_service (** kwargs )
198212 except Exception :
199213 LOG .warning (
200- "The Geometry service could not be started locally."
214+ "The Geometry DMS service could not be started locally."
201215 " Trying to start Ansys SpaceClaim locally."
202216 )
203217
@@ -962,3 +976,128 @@ def _launch_pim_instance(
962976 logging_level = client_log_level ,
963977 logging_file = client_log_file ,
964978 )
979+
980+
981+ def launch_modeler_with_core_service (
982+ product_version : int = None ,
983+ host : str = "localhost" ,
984+ port : int = None ,
985+ enable_trace : bool = False ,
986+ timeout : int = 60 ,
987+ server_log_level : int = 2 ,
988+ client_log_level : int = logging .INFO ,
989+ server_logs_folder : str = None ,
990+ client_log_file : str = None ,
991+ ** kwargs : dict | None ,
992+ ) -> "Modeler" :
993+ """Start the Geometry Core service locally using the ``ProductInstance`` class.
994+
995+ When calling this method, a standalone Geometry Core service is started.
996+ By default, if an endpoint is specified (by defining `host` and `port` parameters)
997+ but the endpoint is not available, the startup will fail. Otherwise, it will try to
998+ launch its own service.
999+
1000+ Parameters
1001+ ----------
1002+ product_version: int, optional
1003+ The product version to be started. Goes from v25.2 to
1004+ the latest. Default is ``None``.
1005+ If a specific product version is requested but not installed locally,
1006+ a SystemError will be raised.
1007+
1008+ **Ansys products versions and their corresponding int values:**
1009+
1010+ * ``252`` : Ansys 25R2
1011+ * ``261`` : Ansys 26R1
1012+ host: str, optional
1013+ IP address at which the service will be deployed. By default,
1014+ its value will be ``localhost``.
1015+ port : int, optional
1016+ Port at which the service will be deployed. By default, its
1017+ value will be ``None``.
1018+ enable_trace : bool, optional
1019+ Boolean enabling the logs trace on the service console window.
1020+ By default its value is ``False``.
1021+ timeout : int, optional
1022+ Timeout for starting the backend startup process. The default is 60.
1023+ server_log_level : int, optional
1024+ Backend's log level from 0 to 3:
1025+ 0: Chatterbox
1026+ 1: Debug
1027+ 2: Warning
1028+ 3: Error
1029+
1030+ The default is ``2`` (Warning).
1031+ client_log_level : int, optional
1032+ Logging level to apply to the client. By default, INFO level is used.
1033+ Use the logging module's levels: DEBUG, INFO, WARNING, ERROR, CRITICAL.
1034+ server_logs_folder : str, optional
1035+ Sets the backend's logs folder path. If nothing is defined,
1036+ the backend will use its default path.
1037+ client_log_file : str, optional
1038+ Sets the client's log file path. If nothing is defined,
1039+ the client will log to the console.
1040+ **kwargs : dict, default: None
1041+ Placeholder to prevent errors when passing additional arguments that
1042+ are not compatible with this method.
1043+
1044+ Returns
1045+ -------
1046+ Modeler
1047+ Instance of the Geometry Core service.
1048+
1049+ Raises
1050+ ------
1051+ ConnectionError
1052+ If the specified endpoint is already in use, a connection
1053+ error will be raised.
1054+ SystemError
1055+ If there is not an Ansys product 25.2 version or later installed
1056+ a SystemError will be raised.
1057+
1058+ Examples
1059+ --------
1060+ Starting a geometry core service with the default parameters and getting back a ``Modeler``
1061+ object:
1062+
1063+ >>> from ansys.geometry.core import launch_modeler_with_core_service
1064+ >>> modeler = launch_modeler_with_core_service()
1065+
1066+ Starting a geometry service, on address ``10.171.22.44``, port ``5001``, with chatty
1067+ logs, traces enabled and a ``300`` seconds timeout:
1068+
1069+ >>> from ansys.geometry.core import launch_modeler_with_core_service
1070+ >>> modeler = launch_modeler_with_core_service(host="10.171.22.44",
1071+ port=5001,
1072+ enable_trace= True,
1073+ timeout=300,
1074+ server_log_level=0)
1075+ """
1076+ # if api_version is passed, throw a warning saying that it is not used
1077+ if "api_version" in kwargs :
1078+ LOG .warning (
1079+ "The 'api_version' parameter is not used in 'launch_modeler_with_core_service'. "
1080+ "Please remove it from the arguments."
1081+ )
1082+
1083+ # If we are in a Windows environment, we are going to write down the server
1084+ # logs in the %PUBLIC%/Documents/Ansys/GeometryService folder.
1085+ if os .name == "nt" and server_logs_folder is None :
1086+ # Writing to the "Public" folder by default - no write permissions specifically required.
1087+ server_logs_folder = Path (os .getenv ("PUBLIC" ), "Documents" , "Ansys" , "GeometryService" )
1088+ LOG .info (f"Writing server logs to the default folder at { server_logs_folder } ." )
1089+
1090+ return prepare_and_start_backend (
1091+ BackendType .LINUX_SERVICE ,
1092+ product_version = product_version ,
1093+ host = host ,
1094+ port = port ,
1095+ enable_trace = enable_trace ,
1096+ api_version = ApiVersions .LATEST ,
1097+ timeout = timeout ,
1098+ server_log_level = server_log_level ,
1099+ client_log_level = client_log_level ,
1100+ server_logs_folder = server_logs_folder ,
1101+ client_log_file = client_log_file ,
1102+ specific_minimum_version = 252 ,
1103+ )
0 commit comments