Use an existing session#
If a session of Discovery, SpaceClaim, or the Geometry service is already running, PyAnsys Geometry can be used to connect to it.
Warning
Running a SpaceClaim or Discovery normal session does not suffice to be able to use it with PyAnsys Geometry. Both products need the ApiServer extension to be running. In this case, to ease the process, you should launch the products directly from the PyAnsys Geometry library as shown in Launch a local session.
Establish the connection#
From Python, establish a connection to the existing client session by creating a Modeler object:
from ansys.geometry.core import Modeler
modeler = Modeler(host="localhost", port=50051, transport_mode="wnua") # On Windows
# or
modeler = Modeler(host="localhost", port=50051, transport_mode="uds") # On Linux
# or
modeler = Modeler(host="localhost", port=50051, transport_mode="insecure") # For any OS using insecure gRPC
If no error messages are received, your connection is established successfully. Note that your local port number might differ from the one shown in the preceding code.
Warning
When running a Windows Docker container, certain high-value ports might be restricted
from its use. This means that the port exposed by the container has to be set
to lower values. You should change the value of ANSRV_GEO_PORT
to use a port such as 700, instead of 50051.
You can check the restricted port ranges with netsh int ipv4 show excludedportrange protocol=tcp
in a Windows command prompt.
Note
Starting from PyAnsys Geometry 0.14, the transport_mode parameter is required.
For detailed information about available transport modes, secure connections, and
compatibility with different Ansys releases, see Securing connections.
Verify the connection#
If you want to verify that the connection is successful, request the status of the client
connection inside your Modeler object:
>>> modeler.client
Ansys Geometry Modeler Client (...)
Target: localhost:50051
Connection: Healthy