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:
hoststr, default: DEFAULT_HOST

Host where the server is running.

portUnion[str, int], default: DEFAULT_PORT

Port number where the server is running.

channelChannel, default: None

gRPC channel for server communication.

remote_instanceansys.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_instanceLocalDockerInstance, default: None

Corresponding local Docker instance when the Geometry service is launched using the launch_docker_modeler method. This instance is deleted when the GrpcClient.close method is called.

product_instanceProductInstance, 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 the launch_modeler_with_spaceclaim() interface. This instance will be deleted when the GrpcClient.close method is called.

timeoutReal, default: 120

Time in seconds for trying to achieve the connection.

logging_levelint, default: INFO

Logging level to apply to the client.

logging_filestr, Path, default: None

File to output the log to, if requested.

Overview#

create_design

Initialize a new design with the connected client.

get_active_design

Get the active design on the modeler object.

read_existing_design

Read the existing design on the service with the connected client.

close

Access the client’s close method.

exit

Access the client’s close method.

open_file

Open a file.

run_discovery_script_file

Run a Discovery script file.

get_service_logs

Get the service logs.

client

Modeler instance client.

designs

All designs within the modeler workspace.

repair_tools

Access to repair tools.

prepare_tools

Access to prepare tools.

measurement_tools

Access to measurement tools.

__repr__

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:
namestr

Name for the new design.

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:
sync_with_backendbool, default: True

Whether to sync the active design with the remote service. If set to False, the active design may be out-of-sync with the remote service. This is useful when the active design is known to be up-to-date.

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.close(close_designs: bool = True) None#

Access the client’s close method.

Parameters:
close_designsbool, default: True

Whether to close all designs before closing the client.

Modeler.exit(close_designs: bool = True) None#

Access the client’s close method.

Parameters:
close_designsbool, default: True

Whether to close all designs before closing the client.

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_pathstr, 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_optionsImportOptions

Import options that toggle certain features when opening a file.

Returns:
Design

Newly imported design.

Modeler.__repr__() str#

Represent the modeler as a string.

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 arguments run_discovery_script_file(..., script_args = {"length": "20"}, ...), the script will receive the dictionary argsDict 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 called result with the key-value pair {"numBodies": numBodies}, where numBodies 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 24.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_pathstr | Path

Path of the file. The extension of the file must be included.

script_argsdict[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 to False (default) and the script modifies the current design, the design may be out-of-sync. By default, False.

api_versionint | str | ApiVersions, optional

The scripting API version to use. For example, version 24.1 can be passed as an integer 241, a string “241” 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.

Returns:
dict[str, str]

Values returned from the script.

Design, optional

Up-to-date current design. This is only returned if import_design=True.

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_folderstr, Path or None, 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 to True.

Returns:
str

Service logs as a string. This is returned if the dump_to_file parameter is set to False.

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 to True and the dump_to_file parameter is set to False.

Path

Path to the folder containing the logs (if the all_logs parameter is set to True) or the path to the log file (if only the current logs are retrieved). The dump_to_file parameter must be set to True.