Modeler
#
- class ansys.geometry.core.modeler.Modeler(host: str = DEFAULT_HOST, port: str | int = DEFAULT_PORT, channel: grpc.Channel | None = None, remote_instance: ansys.platform.instancemanagement.Instance | None = None, docker_instance: ansys.geometry.core.connection.docker_instance.LocalDockerInstance | None = None, product_instance: ansys.geometry.core.connection.product_instance.ProductInstance | None = None, timeout: ansys.geometry.core.typing.Real = 120, logging_level: int = logging.INFO, logging_file: pathlib.Path | str | None = None, backend_type: ansys.geometry.core.connection.backend.BackendType | None = None)#
Provides for interacting with an open session of the Geometry service.
- Parameters:
- host
str
, default:DEFAULT_HOST
Host where the server is running.
- port
Union
[str
,int
], default:DEFAULT_PORT
Port number where the server is running.
- channel
Channel
, default:None
gRPC channel for server communication.
- remote_instance
ansys.platform.instancemanagement.Instance
, default:None
Corresponding remote instance when the Geometry service is launched using PyPIM. This instance is deleted when the
GrpcClient.close
method is called.- docker_instance
LocalDockerInstance
, default:None
Corresponding local Docker instance when the Geometry service is launched using the
launch_docker_modeler
method. This instance is deleted when theGrpcClient.close
method is called.- product_instance
ProductInstance
, default:None
Corresponding local product instance when the product (Discovery or SpaceClaim) is launched through the
launch_modeler_with_geometry_service()
,launch_modeler_with_discovery()
or thelaunch_modeler_with_spaceclaim()
interface. This instance will be deleted when theGrpcClient.close
method is called.- timeout
Real
, default: 120 Time in seconds for trying to achieve the connection.
- logging_level
int
, default:INFO
Logging level to apply to the client.
- logging_file
str
,Path
, default:None
File to output the log to, if requested.
- host
Overview#
Initialize a new design with the connected client. |
|
Get the active design on the modeler object. |
|
Read the existing design on the service with the connected client. |
|
Access the client’s close method. |
|
Access the client’s close method. |
|
Open a file. |
|
Run a Discovery script file. |
|
Get the service logs. |
|
|
All designs within the modeler workspace. |
|
Access to repair tools. |
|
Access to prepare tools. |
|
Access to measurement tools. |
Represent the modeler as a string. |
Import detail#
from ansys.geometry.core.modeler import Modeler
Property detail#
- property Modeler.client: ansys.geometry.core.connection.client.GrpcClient#
Modeler
instance client.
- property Modeler.designs: dict[str, ansys.geometry.core.designer.design.Design]#
All designs within the modeler workspace.
Notes
This property is read-only. DO NOT modify the dictionary.
- property Modeler.repair_tools: ansys.geometry.core.tools.repair_tools.RepairTools#
Access to repair tools.
- property Modeler.prepare_tools: ansys.geometry.core.tools.prepare_tools.PrepareTools#
Access to prepare tools.
- property Modeler.measurement_tools: ansys.geometry.core.tools.measurement_tools.MeasurementTools#
Access to measurement tools.
Method detail#
- Modeler.create_design(name: str) ansys.geometry.core.designer.design.Design #
Initialize a new design with the connected client.
- Parameters:
- name
str
Name for the new design.
- name
- Returns:
Design
Design object created on the server.
- Modeler.get_active_design(sync_with_backend: bool = True) ansys.geometry.core.designer.design.Design #
Get the active design on the modeler object.
- Parameters:
- Returns:
Design
Design object already existing on the modeler.
- Modeler.read_existing_design() ansys.geometry.core.designer.design.Design #
Read the existing design on the service with the connected client.
- Returns:
Design
Design object already existing on the server.
- Modeler.exit(close_designs: bool = True) None #
Access the client’s close method.
Notes
This method is calling the same method as
close()
.
- Modeler.open_file(file_path: str | pathlib.Path, upload_to_server: bool = True, import_options: ansys.geometry.core.misc.options.ImportOptions = ImportOptions()) ansys.geometry.core.designer.design.Design #
Open a file.
This method imports a design into the service. On Windows,
.scdocx
and HOOPS Exchange formats are supported. On Linux, only the.scdocx
format is supported.If the file is a shattered assembly with external references, the whole containing folder will need to be uploaded. Ensure proper folder structure in order to prevent the uploading of unnecessary files.
- Parameters:
- file_path
str
,Path
Path of the file to open. The extension of the file must be included.
- upload_to_serverbool
True if the service is running on a remote machine. If service is running on the local machine, set to False, as there is no reason to upload the file.
- import_options
ImportOptions
Import options that toggle certain features when opening a file.
- file_path
- Returns:
Design
Newly imported design.
- Modeler.run_discovery_script_file(file_path: str | pathlib.Path, script_args: dict[str, str] | None = None, import_design: bool = False, api_version: int | str | ansys.geometry.core.connection.backend.ApiVersions = None) tuple[dict[str, str], ansys.geometry.core.designer.design.Design | None] #
Run a Discovery script file.
Note
If arguments are passed to the script, they must be in the form of a dictionary. On the server side, the script will receive the arguments as a dictionary of strings, under the variable name
argsDict
. For example, if the script is called with the argumentsrun_discovery_script_file(..., script_args = {"length": "20"}, ...)
, the script will receive the dictionaryargsDict
with the key-value pair{"length": "20"}
.Note
If an output is expected from the script, it will be returned as a dictionary of strings. The keys and values of the dictionary are the variables and their values that the script returns. However, it is necessary that the script creates a dictionary called
result
with the variables and their values that are expected to be returned. For example, if the script is expected to return the number of bodies in the design, the script should create a dictionary calledresult
with the key-value pair{"numBodies": numBodies}
, wherenumBodies
is the number of bodies in the design.The implied API version of the script should match the API version of the running Geometry Service. DMS API versions 23.2.1 and later are supported. DMS is a Windows-based modeling service that has been containerized to ease distribution, execution, and remotability operations.
- Parameters:
- file_path
str
|Path
Path of the file. The extension of the file must be included.
- script_args
dict
[str
,str
], optional. Arguments to pass to the script. By default,
None
.- import_designbool, optional.
Whether to refresh the current design from the service. When the script is expected to modify the existing design, set this to
True
to retrieve up-to-date design data. When this is set toFalse
(default) and the script modifies the current design, the design may be out-of-sync. By default,False
.- api_version
int
|str
|ApiVersions
,optional
The scripting API version to use. For example, version 23.2 can be passed as an integer 232, a string “232” or using the
ansys.geometry.core.connection.backend.ApiVersions
enum class. By default,None
. When specified, the service will attempt to run the script with the specified API version. If the API version is not supported, the service will raise an error. If you are using Discovery or SpaceClaim, the product will determine the API version to use, so there is no need to specify this parameter.
- file_path
- Returns:
- Raises:
GeometryRuntimeError
If the Discovery script fails to run. Otherwise, assume that the script ran successfully.
Notes
The Ansys Geometry Service only supports scripts that are of the same version as the running service. Any
api_version
input will be ignored.
- Modeler.get_service_logs(all_logs: bool = False, dump_to_file: bool = False, logs_folder: str | pathlib.Path | None = None) str | dict[str, str] | pathlib.Path #
Get the service logs.
- Parameters:
- all_logsbool, default:
False
Flag indicating whether all logs should be retrieved. By default, only the current logs are retrieved.
- dump_to_filebool, default:
False
Flag indicating whether the logs should be dumped to a file. By default, the logs are not dumped to a file.
- logs_folder
str
,Path
orNone
, default:None
Name of the folder where the logs should be dumped. This parameter is only used if the
dump_to_file
parameter is set toTrue
.
- all_logsbool, default:
- Returns:
str
Service logs as a string. This is returned if the
dump_to_file
parameter is set toFalse
.dict
[str
,str
]Dictionary containing the logs. The keys are the logs names, and the values are the logs as strings. This is returned if the
all_logs
parameter is set toTrue
and thedump_to_file
parameter is set toFalse
.Path
Path to the folder containing the logs (if the
all_logs
parameter is set toTrue
) or the path to the log file (if only the current logs are retrieved). Thedump_to_file
parameter must be set toTrue
.