Streamlined API Reference

The classes and functions that form the Streamlined API are grouped by database element, to help you find what you need:

Session level

Session

class Session(service_layer_url: str, user_name: Optional[str] = None, password: Optional[str] = None, domain: Optional[str] = None, autologon: Optional[bool] = None, timeout: int = 300000, existing_session: Optional[GRANTA_MIScriptingToolkit.GRANTA_MISession.GRANTA_MISession] = None, oidc: bool = False, auth_token: Optional[str] = None, refresh_token: Optional[str] = None, use_stored_token: bool = False)

Represents a Granta MI Session. Allows the MI Scripting Toolkit to make calls to the Service Layer, and provides access to and search functions for available databases.

__init__(service_layer_url: str, user_name: Optional[str] = None, password: Optional[str] = None, domain: Optional[str] = None, autologon: Optional[bool] = None, timeout: int = 300000, existing_session: Optional[GRANTA_MIScriptingToolkit.GRANTA_MISession.GRANTA_MISession] = None, oidc: bool = False, auth_token: Optional[str] = None, refresh_token: Optional[str] = None, use_stored_token: bool = False)None
Parameters
  • service_layer_url – str

  • user_name – str

  • password – str

  • domain – str

  • autologon – bool

  • timeout – int (maximum time to wait for a response, in milliseconds)

  • existing_session – Foundation API GRANTA_MIScriptingToolkit.GRANTA_MISession class

  • oidc – bool (Contact Ansys Granta Technical Support for OIDC configuration and setup documentation)

  • auth_token – str

  • refresh_token – str

  • use_stored_token – bool

Returns

None

update(records: List[Record], update_attributes: bool = True, update_links: bool = False, refresh_attributes: bool = True)List[Record]

Pushes any changes in the specified records (including adding newly-created records) to the server. Returns a list of successfully imported Record objects. If refresh_attributes set to True, the imported records’ attributes are exported after the update is complete.

Parameters
  • records – List[Record]

  • update_links – bool

  • update_attributes – bool

  • refresh_attributes – bool

Returns

List[Record]

Pushes any changes in the links of the specified records (including newly-created records) to the server. Returns a list of successfully modified Record objects. All source and target records must be exported to/from the server before being linked.

Parameters

records – List[Record]

Returns

List[Record]

spawn_session()Optional[GRANTA_MIScriptingToolkit.GRANTA_MISession.GRANTA_MISession]

Creates a new Foundation API GRANTA_MIScriptingToolkit.GRANTA_MISession object using the credentials of the current Session.

Returns

Foundation API GRANTA_MIScriptingToolkit.GRANTA_MISession class

property viewer_base_url

MI Viewer URL associated with the Service Layer.

Returns

str

can_connect()bool

Checks whether credentials have been provided to the server.

Returns

bool

connect()GRANTA_MIScriptingToolkit.GRANTA_MISession.GRANTA_MISession

Returns a Foundation API GRANTA_MIScriptingToolkit.GRANTA_MISession object using the current Session’s credentials.

Returns

Foundation API GRANTA_MIScriptingToolkit.GRANTA_MISession class

persist_oidc_token()None

Stores a refresh token in the credential manager for your system for unattended later use. The keyring package uses system-managed storage, and supports the following credential managers:

  • Windows Credential Manager

  • macOS Keychain

  • Freedesktop Secret Service

  • KDE4 and KDE5 KWallet

Returns

None

refetch_dbs()None

Fetches the list of databases from the server. Makes a Service Layer call.

Returns

None

property dbs

List of databases on the server.

Returns

List[Database]

get_db(name: str = None, db_key: str = None)Database

Returns the database with name name and/or database key db_key.

Raises a KeyError if multiple databases are found for the same criteria.

Parameters
  • name – str

  • db_key – str

Returns

Database object

search_for_records_by_name(name: str)List[Record]

Searches by record name over all databases (uses Database.search_for_records_by_name()). Makes a Service Layer call for each table in each database.

Parameters

name – str

Returns

List[Record]

search_for_records_by_text(text: str)List[Record]

Performs a simple text search over all databases (uses Database.search_for_records_by_text()). Makes a Service Layer call for each table in each database.

Parameters

text – str

Returns

List[Record]

records_from_string(text: str)List[Record]

Generates Record objects from a string in MI clipboard format (version 12 or higher).

Note

Required string format is .tsv with column headers RecordHistoryGuid, RecordGuid, Table, DatabaseKey and RecordFullName.

Parameters

text – str

Returns

List[Record]

get_record_by_id(db_key: str, hguid: str = None, vguid: str = None, identity: int = None)Record

Returns the record with the specified ID from the database specified by db_key. If more than one ID is provided, the method looks for identity first, then vguid and hguid.

Parameters
  • db_key – str

  • hguid – str (Record History GUID, uniquely identifies record)

  • vguid – str (Record GUID, uniquely identifies record version)

  • identity – int (Record identifier)

Returns

Record object

bulk_fetch_release_states(records: List[Record], batch_size: int = 100, parallelise: bool = False, max_num_threads: int = 6)None

Fetches and populates the release states of the specified Record objects.

Parameters
  • records – List[Record]

  • batch_size – int (default value of 100)

  • parallelise – bool

  • max_num_threads – int (default value of 6)

Returns

None

bulk_delete_or_withdraw_records(records: List[Record], batch_size: int = 100, parallelise: bool = False, max_num_threads: int = 6, update_release_states: bool = False)None

Deletes records from the server (or withdraws them, if in a version-controlled table). Record release states can also be updated using this method.

Parameters
  • records – List[Record]

  • batch_size – int (default value of 100)

  • parallelise – bool

  • max_num_threads – int (default value of 6)

  • update_release_states – bool

Returns

None

get_async_job_queue(queue_url: str = None, verify_ssl: bool = True, ssl_ca_bundle: Union[str, pathlib.Path] = None)AsyncJobQueue

Creates an AsyncJobQueue object from this Session.

Parameters
  • queue_url – str (URL of the Job Queue if not the same as the Service Layer, extracted from mi_session otherwise)

  • verify_ssl – bool (Whether to verify SSL connections to the remote server; True by default)

  • ssl_ca_bundle – Union[str, pathlib.Path] (optional) (Path to custom CA bundle (.crt or .pem); use if your MI installation has a self-signed certificate which is not trusted by the requests module)

Returns

AsyncJobQueue object

AttributeFetcher

class AttributeFetcher(table: Table, batch_size: int = 100, attributes: List[Union[str, AttributeDefinition, PseudoAttributeDefinition]] = None, records: List[Record] = None, max_parallel_threads: int = 6)

Bulk exporter for record data. Fetches data values for all named AttributeDefinition and PseudoAttributeDefinition objects from the specified Record objects and Table.

Set attributes to None to export all record data.

A class method executes the data export, allowing the AttributeFetcher to be edited post-creation.

__init__(table: Table, batch_size: int = 100, attributes: List[Union[str, AttributeDefinition, PseudoAttributeDefinition]] = None, records: List[Record] = None, max_parallel_threads: int = 6)None
Parameters
Returns

None

property records

List of records to be fetched (exported).

Returns

List[Record]

property attribute_list

List of attributes for which data will be fetched (exported).

Returns

List[Union[AttributeDefinition, PseudoAttributeDefinition]]

fetch_attribute_data(parallelise: bool = False)None

Fetch the attribute data for the provided records and attributes, and populate the corresponding AttributeValue objects for each record.

Parameters

parallelise – bool

Returns

None

AssociatedRecordFetcher

class AssociatedRecordFetcher(table: Table, records: List[Record], target_table: Table, link_direction: str = 'Both', attribute_path: List[AttributeDefinition] = None, batch_size: int = 100)

Bulk fetcher for associated records. Fetches all Record objects via association chains from the specified Record objects in the target Table. Provides means to choose the direction that association chains are followed, and to specify a list of tabular attributes which are chained together.

A class method executes the fetch, allowing the AssociatedRecordFetcher to be edited post-creation.

__init__(table: Table, records: List[Record], target_table: Table, link_direction: str = 'Both', attribute_path: List[AttributeDefinition] = None, batch_size: int = 100)
Parameters
  • tableTable

  • records – List[Record]

  • target_tableTable

  • link_direction – str (Both, Forward, Reverse)

  • attribute_path – List[AttributeDefinition]

  • batch_size – int (default value of 100)

Returns

None

fetch_associated_records(parallelise: bool = False, max_parallel_threads: int = 6)List[Dict[str, Union[Record, List[Record]]]]

Fetch the associated records in the specified Table from the specified Record objects.

Parameters
  • parallelise – bool

  • max_parallel_threads – int (default 6)

Returns

List[Dict[str, Union[Record, List[Record]]]] list of dictionaries with source_record and associated_records fields for each provided Record.

LinkFetcher

class LinkFetcher(table: Table, batch_size: int = 100, records: List[Record] = None, link_groups: List[str] = None)

Bulk record link fetcher (exporter). Fetches and populates record link groups for the specified Record objects in the specified Table. Set link_groups to None to fetch all record link groups.

__init__(table: Table, batch_size: int = 100, records: List[Record] = None, link_groups: List[str] = None)None
Parameters
  • tableTable object

  • batch_size – int (default value of 100)

  • link_groups – List[str]

  • records – List[Record]

Returns

None

List of link groups to export.

Returns

List[str]

property records

List of records to fetch link groups for.

Returns

List[Record]

fetch_linked_records(parallelise: bool = False, max_parallel_threads: int = 6)None

Perform the bulk fetch (export). Batches Service Layer calls into efficient blocks, then populates Record object pseudo-attributes.

Parameters
  • parallelise – bool

  • max_parallel_threads – int (default value of 6)

Returns

None

ReleaseStateFetcher

class ReleaseStateFetcher(session: GRANTA_MIScriptingToolkit.granta.mi.Session, records: List[Record], batch_size: int = 100, max_parallel_threads: int = 6)

Allows record release states to be fetched from the server in bulk.

The list of Record objects, batch size, and number of threads in parallel can be edited post-creation.

A class method fetches the release states and populates the relevant Record properties.

__init__(session: GRANTA_MIScriptingToolkit.granta.mi.Session, records: List[Record], batch_size: int = 100, max_parallel_threads: int = 6)None
Parameters
  • batch_size – int (default value of 100)

  • records – List[Record]

  • max_parallel_threads – int (default value of 6)

Returns

None

property records

List of Record objects to be processed.

Returns

List[Record]

fetch_release_states(parallelise: bool = False)None

Fetches the release states of the specified Record objects from the server, and populates their relevant properties.

Parameters

parallelise – bool (splits operation into multiple threads if set to True)

Returns

None

BulkRecordDeleterWithdrawer

class BulkRecordDeleterWithdrawer(session: GRANTA_MIScriptingToolkit.granta.mi.Session, records: List[Record], batch_size: int = 100, max_parallel_threads: int = 6)

Allows for bulk deletion or withdrawal or records from the server. Records are withdrawn from version-controlled tables, otherwise they are deleted.

The deletion/withdrawal is performed by a method on the class; as such, the list of Record objects for deletion, batch size, and number of threads in parallel can be edited post-creation.

__init__(session: GRANTA_MIScriptingToolkit.granta.mi.Session, records: List[Record], batch_size: int = 100, max_parallel_threads: int = 6)None
Parameters
  • sessionSession object

  • batch_size – int (default value of 100)

  • records – List[Record]

  • max_parallel_threads – int (default value of 6)

Returns

None

property records

List of records to be deleted or withdrawn.

Returns

List[Record]

delete_or_withdraw(parallelise: bool = False)None

Performs the deletion (or withdrawal, if the records are in a version-controlled table).

Parameters

parallelise – bool (splits operation into multiple threads if True)

Returns

None

Database and Table level

Database

class Database(_gdl_obj: GRANTA_MIScriptingToolkit.MIDatabase.MIDatabase, _mi: Session)

Represents an MI database, and provides access to its tables, unit systems, and record link groups.

__init__(_gdl_obj: GRANTA_MIScriptingToolkit.MIDatabase.MIDatabase, _mi: Session)None
Parameters
Returns

None

property parameters

Parameters associated with the database, indexed by name.

Returns

Dict[str, ParameterDefinition]

refetch_unit_systems()None

Fetches the unit systems associated with the database. Makes a Service Layer call.

Returns

None

dimensionally_equivalent_units(unit: str)Dict[str, Dict[str, float]]

Returns all units which are dimensionally equivalent to the specified unit, with conversion factor and offset. Makes a single call to the Service Layer and caches the results.

Example

db.dimensionally_equivalent_units(unit='kg') might return {'g': {'factor': 1000.0, 'offset': 0.0}}.

Parameters

unit – str

Returns

Dict[str, Dict[str, float]]

property unit_systems_available

Names of unit systems associated with the database.

Returns

List[str]

set_unit_system(unit_system: str, absolute_temperatures: bool = False)None

Sets the unit system for the Database object. The default unit system is the same as for the database itself.

Parameters
  • unit_system – str

  • absolute_temperatures – bool (Whether to use absolute temperature units or not)

Returns

None

property absolute_temperatures

Whether the Database uses absolute temperature units (Kelvin/Rankine) or not (Celsius/Fahrenheit).

Returns

bool

property unit_system

Currently selected unit system (default is ‘Database’).

Returns

str

Returns the named Foundation API GRANTA_MIScriptingToolkit.RecordLinkGroupDetail object.

Parameters
Returns

Foundation API GRANTA_MIScriptingToolkit.RecordLinkGroupDetail class

Foundation API GRANTA_MIScriptingToolkit.RecordLinkGroupDetail objects associated with the database.

Returns

List[GRANTA_MIScriptingToolkit.RecordLinkGroupDetail]

All record link groups in the database.

Returns

List[LinkGroupDetails]

property db_key

Database key.

Returns

str

property name

Name of the database.

Returns

str

refresh_tables()None

Updates the list of tables associated with the database. Makes a Service Layer call.

Returns

None

property tables

Tables associated with the database.

Returns

List[Table]

get_table(name: str, subsets: Optional[Set[str]] = None, unit_system: str = 'Database', absolute_temperatures: bool = False)GRANTA_MIScriptingToolkit.granta.mi_tree_classes.Table

Returns the Table object with the specified name. Case-insensitive.

Parameters
  • name – str

  • subsets – Set[str]

  • unit_system – str

  • absolute_temperatures – bool

Returns

Table object

search_for_records_by_name(name: str)List[Record]

Performs a search on record name across the database. Returns only the Record objects whose short or long names are an exact match for name. Case-insensitive.

Makes a separate Service Layer call for each table in the database.

Note: Use Table.search_for_records_by_name() to narrow your search to a single table.

Parameters

name – str

Returns

List[Record]

search_for_records_by_text(text: str)List[Record]

Performs a simple text search across the database for the string provided. Returns a list of matching Record objects.

Makes a separate Service Layer call for each table in the database.

Note: Use Table.search_for_records_by_text() to narrow your search to a single table.

Parameters

text – str

Returns

List[Record]

search_for_records_where(list_of_criteria: List[SearchCriterion], **kwargs)List[Record]

Performs a search against a single criterion or multiple criteria across the database. Returns a list of matching Record objects.

Note: Use Table.search_for_records_where() to narrow your search to a single table.

Parameters
  • list_of_criteria – List[SearchCriterion]

  • kwargs – Set silent=True to ignore errors due to attributes not existing (returns [] if silent==True and no attributes exist)

Returns

List[Record]

get_record_by_id(hguid: str = None, vguid: str = None, identity: int = None)Record

Returns the Record object with the specified identifier or GUID.

Parameters
  • hguid – str (Record History GUID - uniquely identifies record)

  • vguid – str (Record GUID - uniquely identifies record version)

  • identity – int (Record identifier)

Returns

Record object

Table

class Table(_gdl_obj: GRANTA_MIScriptingToolkit.TableDetail.TableDetail, _mi, unit_system: str = 'Database', absolute_temperatures: bool = False)

Represents an MI table, and provides access to records (particularly searching on record properties), exporters and attribute definitions.

Note

Do not create new instances of this class; it represents a pre-existing database structure.

__init__(_gdl_obj: GRANTA_MIScriptingToolkit.TableDetail.TableDetail, _mi, unit_system: str = 'Database', absolute_temperatures: bool = False)None
Parameters
  • _gdl_obj – Foundation API GRANTA_MIScriptingToolkit.TableDetail class

  • _miSession object

  • unit_system – str (Unit system to use in this table, e.g. ‘UK Imperial’)

  • absolute_temperatures – bool (Whether to use absolute temperatures)

Returns

None

property unit_system

Unit system currently in use.

Returns

str

set_display_unit(attribute: Union[str, AttributeDefinitionPoint, AttributeDefinitionRange], unit_symbol: str)None

Sets the display unit for a POIN or RNGE attribute. This only affects display, not import or FEA exporters.

Parameters
  • attribute – Union[str, AttributeDefinitionPoint, AttributeDefinitionRange] (str must be the attribute name)

  • unit_symbol – str

Returns

None

reset_display_unit(attribute: Union[str, AttributeDefinitionPoint, AttributeDefinitionRange])None

Resets the display unit for a POIN or RNGE attribute back to the unit system default.

Parameters

attribute – Union[str, AttributeDefinitionPoint, AttributeDefinitionRange] (str must be the attribute name)

Returns

None

property min_max_type

How table-wide minimum and maximum values of point (POIN), integer (INPT), range (RNGE) and date-time (DTTM) attributes in the table are calculated:

  • None: Does not calculate values (can improve performance when loading tables)

  • Approximate (default): Uses a fast, approximate algorithm

  • Exact: Takes account of current subset and permissions (can be slow on large tables)

Setting this property refreshes all attributes in the table, and makes a Service Layer call.

Returns

str

refresh_subsets()None

Fetches the list of subsets which can be applied to this table. Makes a Service Layer call.

Returns

None

property subsets_available

Subsets which can be applied to this table.

Returns

Set[str]

property subsets

Subsets that are currently applied to the Table object. Used for record creation and searching.

Returns

Set[str]

add_subsets(values: Union[Set[str], Tuple[str], List[str]])None

Adds single or multiple subsets to the list of subsets currently applied to the Table object.

Parameters

values – Set[str], Tuple[str] or List[str]

Returns

None

remove_subsets(values: Union[str, List[str], Tuple[str], Set[str]])None

Removes single or multiple subsets from the list of subsets currently associated with the Table object.

Parameters

values – Set[str], Tuple[str] or List[str]

Returns

None

all_records(include_folders: bool = False, include_generics: bool = True)List[Record]

Returns a flattened list of all records in the table and populates the children property of each Record object. Makes a Service Layer call.

Parameters
  • include_folders – bool

  • include_generics – bool

Returns

List[Record]

search_for_records_by_text(text: str)List[Record]

Performs a simple text search within the table for the specified string. Returns a list of matching Record objects. Makes a Service Layer call.

Note: Use Database.search_for_records_by_text() to search across the whole database.

Parameters

text – str

Returns

List[Record]

search_for_records_where(list_of_criteria: List[SearchCriterion], **kwargs)List[Record]

Performs a search against a single criterion or multiple criteria within the table. Returns a list of matching Record objects.

Note

Use Database.search_for_records_where() to search across the whole database.

Parameters
  • list_of_criteria – List[SearchCriterion]

  • kwargs – Set silent=True to ignore errors due to attributes not existing (returns [] if silent==True and no attributes exist)

Returns

List[Record]

property name

Name of the table.

Returns

str

property db_key

Parent database key.

Returns

str

refresh_attributes()None

Performs a Foundation API BrowseService.GetAttributeDetails() request and creates a new set of attributes for the table from the results. Makes a Service Layer call.

Returns

None

property layouts

Fetch and view the layouts available in this table for Granta products.

Returns

Dict[str, TableLayout]

property attributes

All attributes included in the table schema, indexed by name. Meta-attributes are accessible through the meta_attributes property of their parent attribute.

Returns

Dict[str, AttributeDefinition]

property mi

MI Session that was used to create or access the Table object. Used for any Service Layer calls made by the Table.

Returns

Session object

get_attribute_definition(name: str = None, identity: int = None)Union[Attribute, List[Attribute]]

Returns the AttributeDefinition object specified by name or the identifier identity. Meta-attributes are also returned if the identifier is provided.

Parameters
  • name – str (Name of the AttributeDefinition object)

  • identity – int (Attribute identifier)

Returns

AttributeDefinition object or List[AttributeDefinition]

get_record_by_id(identity: int = None, hguid: str = None, vguid: str = None)Union[None, Record]

Returns a Record object specified by identifier or GUID. Can be used to access records outside of the current subsets.

Parameters
  • identity – int (Record identifier)

  • hguid – str (Record History GUID - uniquely identifies record)

  • vguid – str (Record GUID - uniquely identifies record version)

Returns

Record object or None

get_record_by_lookup_value(attribute_name: str, lookup_value: str)Union[None, Record]

Returns a Record object specified by attribute name and a exact match for a short text string (lookup value), provided that:

  • The lookup_value matches exactly one record in the table.

  • The record is in the default subset of the table.

Parameters
  • attribute_name – str

  • lookup_value – str

Returns

Record object or None

property children

Return the children of the Table node. Analogous to Record.children, this returns all the records one level from the Table root.

Returns

List[Record]

search_for_records_by_name(name: str)List[Record]

Performs a search on record name within the table. Returns only the Record objects whose short or long names are an exact match for name. Case-insensitive.

Note

Use Database.search_for_records_by_name() to search across the whole database.

Parameters

name – str

Returns

List[Record]

create_empty_attribute_value(definition: AttributeDefinition)AttributeValue

Create an empty AttributeValue instance for an attribute from its AttributeDefinition. This can subsequently be assigned to a record for import.

Parameters

definitionAttributeDefinition object

Returns

AttributeValue object

create_record(name: str, parent: Union[Record, Table] = None, short_name: str = None, attributes: Dict[str, AttributeValue] = None, folder: bool = False, subsets: Set[str] = {}, release_record: bool = False, color: str = None)Record

Creates a new Record object in the Table. The record will not exist in MI, or be able to be assigned as a parent, until it is pushed to the server.

Parameters
  • name – str (Long name)

  • parentRecord or Table object

  • short_name – str

  • attributes – Dict[str, AttributeValue]

  • folder – bool (Whether the record will be Folder type)

  • release_record – bool (Whether the record will be released when it is next updated)

  • subsets – Set[str] (List of subsets the record will belong to)

  • color – str (Record color)

Returns

Record object

paths_from(paths: List[Dict[str, Union[Record, Table, str, None, List[str]]]])List[Tuple[dict, Record]]

Create multiple paths between specified start and end nodes in the table tree.

Paths are specified as a list of dictionaries with the following structure:

{'starting_node': Union[Table, Record, None, str],
'tree_path': ['list', 'of', 'folders'],
'end_node': '<end node string>',
'color': 'color for all new nodes to be assigned'}

See description of path_from() for further details.

Parameters

paths – List[Dict[str, Union[Record, Table, str, None, List[str]]]]

Returns

List[Tuple[dict, Record]]

path_from(starting_node: Union[Record, Table, None, str], tree_path: List[str], end_node: str = None, color: str = None)Record

Create a path from a node in the table tree (a record or folder) down to a new or existing record.

  • The starting node of the path can be the table root or any record/folder in the tree.

  • Specify the names of the records/folders along the path as a list of strings, e.g. ['Polymers', 'Plastics', 'Thermoplastics' ...]. The last item in this path must be an existing record, but other nodes in the path will be created if they don’t already exist.

  • To create a new record at the end of the path (i.e. to add a new end node), set end_node to the new record name.

  • You can also specify the color of the records in the path.

Parameters
  • starting_node – A Record, or ‘Root’/None. Identifies the node under which the new path will start. Set to 'Root' or None to start the path below the root node of the table tree; set it to an existing record/folder to add the new path below that.

  • tree_pathList[str] The names of the folders & records in the path, e.g. [‘name1’, ‘name2’, …].

  • end_nodestring (Optional) The name of a new record that will be created below the last path node.

  • colorstring (Optional) Sets the color of all folders & records in the path.

Returns

The Record object at the end of the path.

get_records_from_path(starting_node: Union[Record, Table, None, str], tree_path: List[Optional[str]], use_short_names: bool = False)List[Record]

Return all records at the end of a path.

  • The starting node identifies the node immediately above the path. To start the path at the top of the tree, set starting_node to ‘Root’ or to the Table object. To start the path under any other node in the tree, specify the record name as the starting_node.

  • Specify the path as a list of record names e.g. ['Polymers', 'Plastics', 'Thermoplastics' ...].

  • You can include “wildcards” in the path by setting a node to ‘None’ e.g. ['Thermoplastics', 'None', 'Unfilled' ...].

  • By default, the strings specified in the path list are assumed to be record full names; to specify the path using record short names instead, set use_short_names to True.

Example 1:

recs = table.get_records_from_path(table, ['Record 1', None, 'Record 2'])

will return all records that are children of a record named Record 2, that also have Record 1 as a great-grandparent. The grandparent is set as a wildcard, and so any is allowed.

Example 2:

recs = table.get_records_from_path('Root', ['Record 1', 'Record 3', None])

will return all records that are grandchildren of records named Record 3 that also have a great-grandparent called Record 1.

Both of these examples have assumed that Record 1 is a top-level record (and have a starting node as a table object to reflect this), but the method does not require this. The starting node can be any record object in the tree.

Parameters
  • starting_node – any Record in the table tree. To start the path at the root node of the table tree, set this to 'Root', None, or the Table object.

  • tree_path – a list of strings specifying the names of the records in the path. May include ‘None’ as a wildcard.

  • use_short_names – a boolean that specifies whether the strings in the path are the record short names

Returns

returns a list of records

Return type

List[Record]

bulk_fetch(records: List[Record], attributes: List[Union[str, AttributeDefinition, PseudoAttributeDefinition]] = None, batch_size: int = 100, parallelise: bool = False, max_num_threads: int = 6)None

Populates data values for all named AttributeDefinition and PseudoAttributeDefinition objects in the specified Record objects. Set attributes to None to export all record data.

Parameters
Returns

None

Fetches and populates record link groups for the specified Record objects. Set link_groups to None to fetch all record link groups.

Parameters
  • records – List[Record]

  • link_groups – List[str]

  • batch_size – int (default value of 100)

  • parallelise – bool

  • max_num_threads – int (default value of 6)

Returns

None

bulk_fetch_associated_records(records: List[Record], target_table: Table, link_direction: str = 'Both', attribute_path: List[AttributeDefinitionTabular] = None, batch_size: int = 100, parallelise: bool = False, max_num_threads: int = 6)List[Dict[str, Union[Record, List[Record]]]]

Fetches records associated with the specified Record objects from a target Table. Returns a list of dictionaries containing the source record and associated records for each Record provided.

You may specify link_direction to only follow tabular links in the specified direction, or provide a list of AttributeDefinitionTabular objects in attribute_path to follow only those tabular links.

Parameters
  • records – List[Record]

  • target_tableTable

  • link_direction – str (Both (default), Forward, Reverse)

  • attribute_path – List[AttributeDefinitionTabular]

  • batch_size – int (default value of 100)

  • parallelise – bool

  • max_num_threads – int (default value of 6)

Returns

List[Dict[str, Union[Record, List[Record]]]]

get_available_exporters(package: str = None, model: str = None, applicability_tag: str = None)List[Exporter]

Returns exporters available on the table filtered by package, model, and applicability tag value.

Parameters
  • packagestr The target FEA analysis package. For example: ‘NX 10.0’, ‘CATIA V5’.

  • modelstr The material model type. For example, ‘Isotropic’, ‘Linear, temperature-independent, isotropic, thermal, plastic’.

  • applicability_tagstr A tag that identifies the applications for which an exporter is intended to be used. For example, ‘MIMaterialsGateway’, ‘MIViewer’.

Returns

List[Exporter]

LinkGroupDetails

class LinkGroupDetails(link_detail: GRANTA_MIScriptingToolkit.RecordLinkGroupDetail.RecordLinkGroupDetail)

Provides access to the properties of a record link group.

__init__(link_detail: GRANTA_MIScriptingToolkit.RecordLinkGroupDetail.RecordLinkGroupDetail)None
Parameters

link_detail – Foundation API GRANTA_MIScriptingToolkit.RecordLinkGroupDetail class

Returns

None

property name

Name of the record link group.

Returns

str

property table_to

Name of the table from which the link group originates.

Returns

str

property table_from

Name of the table the link group comes from.

Returns

str

property type

Whether the record link group is ‘static’, ‘cross-database’ or ‘dynamic’.

Returns

str

property reverse_name

Name of the record link group in the return direction.

Returns

str

TableLayout

class TableLayout(name: str, table: Table)

Provides a JSON-format display of a Granta layout. You can access this through the layout property.

Note

Do not create new instances of this class manually.

__init__(name: str, table: Table)None
Parameters
  • name – str

  • tableTable object

Returns

None

property name

Layout name.

Returns

str

property layout

JSON-formatted version of the layout.

Returns

List[Dict[str, Union[str, List[str], Dict[str, Union[str, List[str]]]]]]

property categories

List of all the categories (headings) in the layout.

Returns

List[str]

property attributes_by_category

Dictionary of attribute lists, indexed by the layout category they are in.

Returns

Dict[str, List[str]]

Dictionary of link group lists, indexed by the layout category they are in.

Returns

Dict[str, List[str]]

property meta_attributes_by_attribute

Dictionary of meta-attribute lists, indexed by parent attributes.

Returns

Dict[str, List[str]]

meta_attributes_on(attribute_name: str)List[str]

Returns the list of meta-attributes corresponding to a given attribute in this layout.

Parameters

attribute_name – str

Returns

List[str]

Exporter

class Exporter(mi: GRANTA_MIScriptingToolkit.granta.mi.Session, exporter_key: str)
__init__(mi: GRANTA_MIScriptingToolkit.granta.mi.Session, exporter_key: str)None

Represents a Granta MI FEA exporter. FEA exporters are used to export record data from Granta MI into formats supported by CAD and CAE packages.

Parameters
  • mi – Current Session object

  • exporter_key – str (Unique identifier for this exporter)

Returns

None

property default_file_extension

Returns the default file extension as defined by the exporter configuration file.

Returns

str

save(file_path: str, file_name: Optional[str] = None, file_extension: Optional[str] = None)None

Saves the output of the last FEA export to the path provided using the default naming convention and file extension for the exporter; specify a file_name or file_extension to override the defaults.

Parameters
  • file_path – str (File path of the form C:\Users\Username\)

  • file_name – str (Optional - Output file name. Does not require a file extension.)

  • file_extension – str (Optional - Output file extension.)

Returns

None

property default_file_name

Returns the default file name for the last performed export, as defined by the exporter configuration file.

Returns

str

property default_encoding

Returns the default file encoding scheme as defined by the exporter configuration file.

Note

This is returned as a Python-compatible string (e.g. “cp1252”) rather than the .NET codepage “1252”.

Returns

str

property default_bom

Returns the default byte-order mark as defined by the exporter configuration file. If no BOM is required by default, this property is None.

Returns

Union[str, None]

get_parameters_required_for_export(records: List[Record])Dict[str, ParameterDefinition]

Returns a dictionary of all of the parameter definitions the Exporter requires to export the data from the specified list of records, indexed by parameter name.

Parameters

records – List[Record]

Returns

Dict[str, ParameterDefinition]

run_exporter(records: List[Record], stop_before: Union[int, str] = None, parameter_defs: Dict[str, ParameterDefinition] = None, sig_figs: int = None)str

Performs an FEA export on the specified list of records, returning the data representing the records as a string.

Parameters
  • records – List[Record]

  • stop_before – Union[int, str] (Either refers to the index of the transform step (int) or its name (str))

  • parameter_defs – Dict[str, ParameterDefinition]

  • sig_figs – int

Returns

str (Contains data output by the exporter)

export_list_is_valid(records: List[Record])bool

Verifies that a list of records is valid for export.

If the exporter was created from a table search, then this method verifies that all records come from this table. Otherwise, the first record is used to determine which table the exporter belongs to.

Parameters

records – List[Record]

Returns

bool (Whether the specified list of records can be exported with this exporter)

Record level

RecordDataStructure

class RecordDataStructure(name: str, table: Table, short_name: Optional[str] = None, color: Optional[str] = None)

Provides access to all record properties and record-level methods that are not accessed via Foundation API GRANTA_MIScriptingToolkit.RecordReference objects.

__init__(name: str, table: Table, short_name: Optional[str] = None, color: Optional[str] = None)None
Parameters
  • name – str (Long name of record)

  • tableTable object

  • short_name – str (Short name of record)

  • color – str (Color of the record)

Returns

None

property name

Long name of record.

Returns

str

property mi

MI Session that was used to create or access the record. Used for any Service Layer calls made by the Record object.

Returns

Session object

property table_name

Name of parent table.

Returns

str

property db_key

Database key for the database the record belongs to.

Returns

str

Record

class Record(name: str, table: Table, parent: Union[Table, Record] = None, short_name: str = None, attributes: Dict[str, AttributeValue] = None, subsets: Set[str] = None, folder: bool = None, record_color: str = None, release_record: bool = True)

Extends the RecordDataStructure class. Stores and provides access to record attributes, pseudo-attributes, links and children. Provides methods for adding, editing and deleting records, and importing/exporting record data.

New Record objects may be created to represent records that do not currently exist in the database:

  • A name, parent table and session must be specified. name will become the record’s long name; an optional argument can be used to specify the short (tree) name.

  • Records created this way will not exist in the host database until the changes have been pushed to MI (see Session.update()).

Note

Do not create new instances of Record objects for records which are already in the database. Existing records will have Foundation API classes associated with them, from which the Streamlined API will automatically generate and return Record objects as required.

__init__(name: str, table: Table, parent: Union[Table, Record] = None, short_name: str = None, attributes: Dict[str, AttributeValue] = None, subsets: Set[str] = None, folder: bool = None, record_color: str = None, release_record: bool = True)None
Parameters
  • name – str (Long name for new records)

  • tableTable object

  • parentRecord or Table object

  • short_name – str (Short (tree) name for new records)

  • attributes – Dict[str, AttributeValue]

  • subsets – Set[str] (Subsets the record belongs to)

  • folder – bool (Whether the record is ‘Folder’ type)

  • record_color – str (see color())

  • release_record – bool (Release state of the record; True to release next version)

Returns

None

property subsets

Subsets that the record belongs to.

Returns

Set[str]

property flag_for_release

Whether the record will be made available to users when it is next updated.

  • True (default): If changes were made to the Record, a new version will be created, otherwise the unreleased version of the record will be released when the server is updated.

  • False: If changes were made to the Record, a new, unreleased version will be created when the server is updated.

Note

If you do not have the correct permissions to change release states, setting this property will not have the documented effect. Please see the Service Layer documentation for more details.

Returns

bool or None

property color

Color of the record when displayed in MI Viewer and other Granta MI applications.

The accepted record colors are: “Red”, “Maroon”, “Fuchsia”, “Yellow”, “Black”, “Gray”, “Aqua”, “Green” “Navy”, “Purple”, “Blue”, “Silver”, “Lime”, “Olive”, “Teal” and “White”.

Returns

str

property short_name

Short (tree) name of the record.

Returns

str

property parent

Parent record or table of this record.

Returns

Record or Table object

find_parent()None

Finds and sets the parent record or table.

If a Record has been created from a Foundation API GRANTA_MIScriptingToolkit.RecordReference object (for example, an existing database record), its parent may not be defined. This function gets the Foundation API GRANTA_MIScriptingToolkit.TreeRecord object (if it does not already exist) and uses it to create and/or set a parent Record object. If the record is at the highest level, the parent is set as the host Table object instead.

Returns

None

property history_guid

Record History GUID, if it exists. Records can be uniquely identified by their Record History GUID, which will return the latest version the user has access to.

Returns

str or None

property record_guid

Record GUID, if it exists. Each version of a record can be uniquely identified by its Record GUID.

Returns

str or None

property id

Record identifier, if it exists.

Returns

int or None

set_attributes(attributes: Union[Iterable[AttributeValue]])None

Flags attributes to update on the server when Session.update() is next called. If set_attributes() is not called on modified attributes, changes to those attributes will not be transferred to MI.

Parameters

attributes – Union[Iterable[AttributeValue]]

Returns

None

clear_attributes(attributes: Union[Iterable[AttributeValue]])None

Flags attributes to have their data value on the server deleted when Session.update() is next called. Does not delete the local value of flagged attributes, only the data on MI. Supercedes previous set_attributes() calls.

Parameters

attributes – Union[Iterable[AttributeValue]]

Returns

None

property viewer_url

The MI Viewer URL for the record.

Returns

str

property path

Browse tree path for the record as a list of folder short names.

Returns

List[str]

property pseudo_attributes

Pseudo-attributes associated with the record, indexed by name.

Returns

Dict[str, PseudoAttributeValue]

refresh_path()None

Re-calculates the record path within the current table. Makes a Service Layer call.

Returns

None

refresh_properties()None

Refreshes the Foundation API GRANTA_MIScriptingToolkit.TreeRecord object associated with the Record, if it has one. Makes a Service Layer call.

Returns

None

refetch_children()None

Refreshes the list of children belonging to the record. Makes a Service Layer call.

Returns

None

refresh_attributes()None

Checks whether the record’s attributes have changed on the server, and updates the Record object if required. Can also be used to populate attributes. Makes a Service Layer call.

Returns

None

refetch_pseudos()None

Fetches pseudo-attribute data for this record, and updates subsets for the record if not set. Makes a Service Layer call.

Returns

None

property attributes

Attributes associated with the record, indexed by attribute name.

Returns

Dict[str, AttributeValue]

get_attributes(names: List[str] = None, types: List[str] = None, include_attributes: bool = True, include_metas: bool = False, include_pseudos: bool = False, empty: bool = None)List[Union[PseudoAttributeValue, AttributeValue]]

Retrieve a list of attributes from the record.attributes dictionary. You can narrow the results by specifying the attribute names or data types, or the required attribute categories (attribute, meta-attribute, or pseudo-attribute).

If the record.attributes dictionary is empty when get_attributes is called, it will be populated before retrieving any attributes.

Example

r.get_attributes(names=['Density', 'Stress-Strain'], types=['POIN', 'SERI'], include_metas=True) will return all point or functional series attributes or meta-attributes named Density or Stress-Strain from the record.

Parameters
  • names – List[str]

  • types – List[str] (Attribute data types; allowed values are: DISC, DTTM, FILE, FUNC, HLNK, INPT, LOGI, LTXT, PICT, POIN, RNGE, STXT, TABL)

  • include_attributes – bool (whether to retrieve attributes that are not meta-attributes or pseudo-attributes; True by default)

  • include_metas – bool (whether to retrieve meta-attributes; False by default)

  • include_pseudos – bool (whether to retrieve pseudo-attributes; False by default)

  • empty – bool (whether to check if the returned attributes are populated)

Returns

List[Union[PseudoAttributeValue, AttributeValue]]

property type

Record type, one of Folder, Generic, or Record. Record type can only be set to Folder or Record through the MI Scripting Toolkit. If it is set on an existing record, it will have no effect.

Returns

str

all_children(include_folders=False, include_generics=True)List[GRANTA_MIScriptingToolkit.granta.mi_record_classes.Record]

Returns a flattened list of all children of a record and populates the children property of each Record object. Makes a Service Layer call.

Parameters
  • include_folders – bool

  • include_generics – bool

Returns

List[Record]

property children

Children of the current record, one level below.

Returns

List[Record]

Link groups for this Record object, and the records they link to. Smart links may be viewed but not edited through the links property.

Returns

Dict[str, Set[Record]]

get_associated_records(target_table: Table, link_direction: str = 'Both', attribute_path: List[AttributeDefinition] = None)List[Record]

Gets all records in a target table that are linked to the current Record object via tabular data association chains. This can be filtered by link direction and to a specific path.

If attribute_path is provided, then only records from that exact path will be returned. Note that the specified tabular attributes will be the ‘source’ of the tabular link, and there may be tables in the chain with no attributes.

Parameters
  • target_tableTable object

  • link_direction – str (Which direction to follow links in: Both (default), Forward, Reverse)

  • attribute_path – List[AttributeDefinition] (Path of tabular attributes to follow - if None, all paths are followed)

Returns

List[Record]

Adds the specified records to the named record link group and flags those links for update. Links that are not set through this method will not be updated on the server.

Parameters
  • link_name – str

  • records – Iterable[Record]

Returns

None

decache_attributes()None

Removes all attributes from the Record, replacing the attributes property with an empty dictionary.

Returns

None

Removes all links from the Record, setting the links property to None.

Returns

None

property is_folder

Whether the record is a ‘Folder’ type.

Returns

bool

property release_state

Release state of the record. Allowed values are ‘Released’, ‘Superseded’, ‘Withdrawn’, ‘Unreleased’, ‘Unversioned’ or ‘Unknown’.

Returns

str

refetch_record_release_state()None

Fetches the record’s release state from the server. Makes a Service Layer call.

Returns

None

property all_versions

Returns all versions or the record as dictionary of Record objects indexed by version number, and the letter ‘v’, e.g. ‘v1’ or ‘v2’. In a version controlled table this can be many, and in a non-version-controlled table there will only ever be one, with the key ‘v0’.

Returns

Dict[str, Record]

delete_or_withdraw_record_on_server()None

Deletes the record from the server, or withdraws it from a version-controlled table. Makes a Service Layer call.

Returns

None

get_available_exporters(package: str = None, model: str = None, applicability_tag: str = None)List[Exporter]

Returns exporters available for this record filtered by package, model, and applicability tag value.

Parameters
  • package – str (Name of target FEA analysis package, for example ‘NX 10.0’ or ‘CATIA V5’)

  • model – str (Material model type, for example ‘Isotropic’ or ‘Linear, temperature-independent, isotropic, thermal, plastic’)

  • applicability_tag – str (Tag that identifies the MI applications an exporter is intended to be used with, for example, ‘MIMaterialsGateway’ or ‘MIViewer’)

Returns

List[mi.Exporter]

Attribute level

There are two types of attribute object at the attribute level: Attribute Definitions and Attribute Values.

Attribute Definitions

These classes describe how an attribute appears in the schema of a given table. There are ten types.

AttributeDefinition

class AttributeDefinition(name: str, _mi: Session)
__init__(name: str, _mi: Session)None

Base attribute definition class.

Note

Do not create new instances of this class; it represents a pre-existing database structure.

Stores basic information about an attribute, such as data type or possible values. Contains information about the attribute itself, and cannot be used to set attribute values. AttributeDefinition wraps all properties of the Foundation API GRANTA_MIScriptingToolkit.AttributeDetail object, including properties that may not be populated for a given attribute. For example, axis_name will not always be populated, but it will always be included because it is a property of GRANTA_MIScriptingToolkit.AttributeDetail.

Parameters
  • name – str

  • _miSession object

Returns

None

property id

Attribute identifier.

Returns

int

property axis_name

Y-axis name (for functional data attributes only).

Returns

str

property name

Attribute name.

Returns

str

property order

Display order in MI Viewer.

Returns

int

property is_meta

Whether the attribute is a meta-attribute or not.

Returns

bool

property is_meta_for

Name of the parent attribute, if the attribute is a meta-attribute. Returns None if not a meta-attribute.

Returns

str or None

property type

Attribute data type, as a four-character string. Possible attribute types are:

POIN = point,
RNGE = range,
FUNC = float functional,
INPT = integer,
LOGI = logical,
DISC = discrete,
STXT = short text,
LTXT = long text,
DTTM = date time,
HLNK = hyperlink,
PICT = picture,
FILE = file,
DSFN = discrete functional,
MAFN = maths functional (equations and logic),
TABL = tabular.

DSFN and MAFN are not supported by the MI Scripting Toolkit, and appear as UNSUPPORTED DATA TYPE.

Returns

str

property unit

Unit symbol.

Returns

str

property meta_attributes

Meta-attributes associated with this attribute, indexed by name.

Returns

Dict[str, AttributeDefinition]

search_criterion(less_than: float = None, greater_than: float = None, contains: Union[str, bool] = None, contains_any: List[str] = None, contains_all: List[str] = None, does_not_contain: str = None, exists: bool = None, equal_to: int = None, between_dates: Tuple[Union[str, datetime.datetime], Union[str, datetime.datetime]] = None, in_column: str = None)Optional[SearchCriterion]

Creates a search criterion for use with Table.search_for_records_where() or Database.search_for_records_where(). Operator priority is the same as the order of the arguments.

Parameters
  • less_than – float

  • greater_than – float

  • contains – Union[str, bool]

  • contains_any – List[str]

  • contains_all – List[str]

  • does_not_contain – str

  • exists – bool

  • equal_to – int

  • between_dates – Union[str, datetime.datetime] (Two dates in chronological order, str must be in YYYY-MM-DD format)

  • in_column – str (Name of tabular column to search)

Returns

SearchCriterion object

AttributeDefinitionDiscrete

class AttributeDefinitionDiscrete(name: str, _mi: Session)
__init__(name: str, _mi: Session)None

Extended AttributeDefinition class for discrete attributes.

Provides a method to view the possible discrete values of an attribute.

Parameters
  • name – str

  • _miSession object

Returns

None

property discrete_values

All possible discrete values of the attribute.

Returns

List[str]

property is_multivalued

Whether this attribute allows multiple values to be set.

Returns

bool

AttributeDefinitionMultiValue

class AttributeDefinitionMultiValue(name: str, _mi: Session)
__init__(name: str, _mi: Session)None

Extended AttributeDefinition class for functional and point data attributes.

Provides access to functional data parameters.

Parameters
  • name – str

  • _miSession object

Returns

None

property parameters

Parameters associated with the attribute, indexed by name.

Returns

Dict[str, ParameterDefinition]

AttributeDefinitionPoint

class AttributeDefinitionPoint(name: str, _mi: Session)
__init__(name: str, _mi: Session)None

Extended AttributeDefinitionMultiValue class for point attributes.

Provides access to point-specific information and methods.

Parameters
  • name – str

  • _miSession object

Returns

None

property max

Maximum value of the data attribute. Affected by user read permissions.

Returns

Union[float, int, datetime.datetime]

property min

Minimum value of the data attribute. Affected by user read permissions.

Returns

Union[float, int, datetime.datetime]

AttributeDefinitionRange

class AttributeDefinitionRange(name: str, _mi: Session)
__init__(name: str, _mi: Session)None

Extended AttributeDefinition class for range attributes.

Provides access to range-specific information and methods.

Parameters
  • name – str

  • _miSession object

Returns

None

property max

Maximum value of the data attribute. Affected by user read permissions.

Returns

Union[float, int, datetime.datetime]

property min

Minimum value of the data attribute. Affected by user read permissions.

Returns

Union[float, int, datetime.datetime]

AttributeDefinitionInteger

class AttributeDefinitionInteger(name: str, _mi: Session)
__init__(name: str, _mi: Session)None

Extended AttributeDefinition class for integer attributes.

Provides access to integer-specific information, such as minmax.

Parameters
  • name – str

  • _miSession object

Returns

None

property max

Maximum value of the data attribute. Affected by user read permissions.

Returns

Union[float, int, datetime.datetime]

property min

Minimum value of the data attribute. Affected by user read permissions.

Returns

Union[float, int, datetime.datetime]

AttributeDefinitionDatetime

class AttributeDefinitionDatetime(name: str, _mi: Session)
__init__(name: str, _mi: Session)None

Extended AttributeDefinition class for date-time attributes.

Provides access to type-specific information, such as minmax.

Parameters
  • name – str

  • _miSession object

Returns

None

property max

Maximum value of the data attribute. Affected by user read permissions.

Returns

Union[float, int, datetime.datetime]

property min

Minimum value of the data attribute. Affected by user read permissions.

Returns

Union[float, int, datetime.datetime]

AttributeDefinitionTabular

class AttributeDefinitionTabular(name: str, _mi: Session)
__init__(name: str, _mi: Session)None

Extended AttributeDefinition class for tabular data attributes.

Provides access to tabular-specific information and methods, such as columns, linking attribute and cross-table links.

Parameters
  • name – str

  • _miSession object

Returns

None

property linking_attribute

Linking attribute, a short text-type attribute used to link rows in the tabular data attribute to records. Returns None for purely local tabular data.

Returns

AttributeDefinition object or None

property linking_table

Table object which the linking attribute belongs to. Returns None for purely local tabular data.

Returns

Table object or None

property column_types

Data type in each column.

Example

['STXT', 'POIN', 'DISC']

Returns

List[str]

property column_histories

The revision histories of each column, as an ordered list of ObjectHistory objects.

Returns

List[ObjectHistory]

property column_units

Unit symbols for each column.

Returns

List[str]

property discrete_values

All possible discrete values, for all columns with the discrete data type.

Returns

List[List[str]]

property column_targets

Column meta-types. Possible column targets are:

Local - Contains local data
TargetAttribute - Contains data from a linked attribute
TargetRecord - Contains the records that the rows link to
TargetTabularColumn - Contains data from a linked tabular column
Unavailable - Data cannot be viewed, usually due to version control or permissions
Returns

List[str]

property columns

Column names (headers).

Returns

List[str]

AttributeDefinitionUnsupported

class AttributeDefinitionUnsupported(name: str, _mi: Session)
__init__(name: str, _mi: Session)None

Extended AttributeDefinition class for unsupported attribute types (maths functional (equations and logic), discrete functional).

Provides access to the limited information available for unsupported attribute types (name, type and unit, if present).

Parameters
  • name – str

  • _miSession object

Returns

None

PseudoAttributeDefinition

class PseudoAttributeDefinition(name: str)
__init__(name: str)None

Stores basic information about a pseudo-attribute.

Note

name must exist in the pseudo_attributes_definition dictionary.

Parameters

name – str

Returns

None

property id

Attribute identifier (this is always 0 for pseudo-attributes).

Returns

int

property read_only

Whether the current user has the correct permissions to edit the attribute.

Returns

bool

property unit

Unit symbol for the pseudo-attribute.

Returns

str

property name

Name of the pseudo-attribute.

Returns

str

property type

Data type of the pseudo-attribute (four-character string).

Returns

str

Attribute Values

These classes are attribute objects that contain data. There is (at least) one for each type.

AttributeValue

class AttributeValue(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Stores and provides access to attribute data values.

Note

Do not create new instances of this class; it represents a pre-existing database structure, and empty instances are provided when needed.

The attributes in a Record are represented in the MI Scripting Toolkit by AttributeDefinition objects, with an associated AttributeValue object containing the attribute’s data. AttributeValue is the base class, and each attribute type has a specialised class that inherits from it.

Note

The ‘Notes’ meta-attribute, common to all attributes, is not accessible through the MI Scripting Toolkit.

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

property value

Current value of the attribute. Can be modified for most attribute types to edit the attribute value. The exceptions are functional, point, tabular and binary (File or Picture) attributes. The value property of these classes always returns the current instance of the class and cannot be modified.

Returns

Union[List[str], str, Dict[str, float], int, bool, BinaryType, AttributeBinary, AttributeFunctional, AttributeTabular, AttributePoint]

is_empty()bool

Checks whether the attribute value is populated.

Returns

bool

property definition

AttributeDefinition associated with this AttributeValue.

Returns

AttributeDefinition object

property id

Attribute identifier.

Returns

int

property is_meta

Whether the attribute is a meta-attribute.

Returns

bool

property is_meta_for

Name of the parent attribute, if a meta-attribute. Returns None if not.

Returns

str or None

property meta_attributes

Meta-attributes associated with this attribute. Does not make calls to the Service Layer.

Returns

Dict[str, AttributeValue]

property name

Attribute name.

Returns

str

abstract property type

Attribute data type, as a four-character string. Possible attribute types are:

POIN = point,
RNGE = range,
FUNC = float functional,
INPT = integer,
LOGI = logical,
DISC = discrete,
STXT = short text,
LTXT = long text,
DTTM = date time,
HLNK = hyperlink,
PICT = picture,
FILE = file,
DSFN = discrete functional,
MAFN = maths functional (equations and logic),
TABL = tabular.

DSFN and MAFN are not supported by the MI Scripting Toolkit, and appear as UNSUPPORTED DATA TYPE.

Returns

str

property unit

Unit symbol.

Returns

str

property is_applicable

Whether the attribute is applicable to the current record. Setting this to False will clear any data values on the attribute.

Returns

bool

AttributeBinary

class AttributeBinary(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None, path: str = None, content_type: str = None)

Extended AttributeValue class to handle BinaryType objects as attribute data values.

Provides access to BinaryType object methods and properties.

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None, path: str = None, content_type: str = None)None
Parameters
Returns

None

property url

Hosted URL of the file. Returns None if not populated.

Returns

str or None

property mime_file_type

MIME (Multipurpose Internet Mail Extensions) file type, if populated.

Some commonly-used extensions are:

image/png - .png
image/gif - .gif
image/bmp - .bmp
image/tiff - .tif, .tiff
text/plain - .txt
application/zip - .zip
application/pdf - .pdf
application/vnd.ms-excel - .xls
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet - .xlsx
application/vnd.ms-powerpoint - .ppt
application/vnd.openxmlformats-officedocument.presentationml.presentation - .pptx
application/msword - .doc
application/vnd.openxmlformats-officedocument.wordprocessingml.document - .docx
Returns

str

is_empty()bool

Checks if the BinaryType object is populated by checking if it contains any binary data.

Returns

bool

property binary_data

Returns the file as a bytes object, or None if unset.

Returns

bytes or None.

AttributePicture

class AttributePicture(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Extended AttributeBinary class for handling Picture objects.

Provides access to Picture save/load methods.

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

property type

Attribute data type, as a four-character string. Possible attribute types are:

POIN = point,
RNGE = range,
FUNC = float functional,
INPT = integer,
LOGI = logical,
DISC = discrete,
STXT = short text,
LTXT = long text,
DTTM = date time,
HLNK = hyperlink,
PICT = picture,
FILE = file,
DSFN = discrete functional,
MAFN = maths functional (equations and logic),
TABL = tabular.

DSFN and MAFN are not supported by the MI Scripting Toolkit, and appear as UNSUPPORTED DATA TYPE.

Returns

str

property mime_file_type

MIME (Multipurpose Internet Mail Extensions) file type, if populated.

Some commonly-used extensions are:

image/png - .png
image/gif - .gif
image/bmp - .bmp
image/tiff - .tif, .tiff
text/plain - .txt
application/zip - .zip
application/pdf - .pdf
application/vnd.ms-excel - .xls
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet - .xlsx
application/vnd.ms-powerpoint - .ppt
application/vnd.openxmlformats-officedocument.presentationml.presentation - .pptx
application/msword - .doc
application/vnd.openxmlformats-officedocument.wordprocessingml.document - .docx
Returns

str

save(path: Union[str, pathlib.Path], file_name: Optional[str] = None)None

Wraps the Picture.save() method.

Parameters
  • path – Union[str, pathlib.Path] (Path where the image should be saved. Takes the form C:\Users\yourname\Pictures\image.jpg or /home/username/Pictures/image.jpg Deprecated: Path to the folder where the image should be saved. Requires separate file_name parameter. Takes the form C:\Users\yourname\Pictures\ or /home/username/Pictures/)

  • file_name – str (Name of new image file, with extension)

Returns

None

load(path: Union[str, pathlib.Path], file_name: Optional[str] = None)None

Wraps the Picture.load() method (populates the Picture object with the specified image file).

Parameters
  • path – Union[str, pathlib.Path] (Path to the image file to be imported. Takes the form C:\Users\yourname\Pictures\image.jpg or /home/username/Pictures/image.jpg Deprecated: Path to the folder containing the file to be imported. Takes the form C:\Users\yourname\Pictures\ or /home/username/Pictures/)

  • file_name – str (File name, with extension)

Returns

None

AttributeFile

class AttributeFile(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Extended AttributeBinary class to handle File objects.

Provides access to File object save/load methods, file name, and description.

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

property type

Attribute data type, as a four-character string. Possible attribute types are:

POIN = point,
RNGE = range,
FUNC = float functional,
INPT = integer,
LOGI = logical,
DISC = discrete,
STXT = short text,
LTXT = long text,
DTTM = date time,
HLNK = hyperlink,
PICT = picture,
FILE = file,
DSFN = discrete functional,
MAFN = maths functional (equations and logic),
TABL = tabular.

DSFN and MAFN are not supported by the MI Scripting Toolkit, and appear as UNSUPPORTED DATA TYPE.

Returns

str

save(path: Optional[Union[str, pathlib.Path]] = None, file_name: Optional[str] = None)None

Wraps the File.save() method.

Parameters
  • path – Union[str, pathlib.Path] (Path where the file should be saved. Takes the form C:\Users\yourname\Documents\file.pdf or /home/username/Documents/file.pdf Deprecated: Path to the folder where the file should be saved. Requires separate file_name parameter. Takes the form C:\Users\yourname\Documents\ or /home/username/Documents/)

  • file_name – str (Deprecated: New file name, with extension)

Returns

None

load(path: Optional[Union[str, pathlib.Path]] = None, file_name: Optional[str] = None)None

Wraps the File.load() method (populates the File object with the specified file).

Parameters
  • path – Union[str, pathlib.Path] (Path to the file to be imported. Takes the form C:\Users\yourname\Documents\file.pdf or /home/username/Documents/file.pdf Deprecated: Path to the folder containing the file to be imported. Requires separate file_name parameter. Takes the form C:\Users\yourname\Documents\ or /home/username/Documents/)

  • file_name – str (File name, with extension)

Returns

None

property file_name

Name of the file associated with the File object. Displayed in MI applications.

Returns

str

property description

Description of the file displayed in MI applications.

Returns

str

AttributeDate

class AttributeDate(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Extended AttributeValue class for date-time attributes.

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

property value_as_string

Return the value of the date attribute as a string.

Returns

str

property value

Return the value of the date attribute as a datetime.datetime object.

Returns

datetime.datetime object

property type

Attribute data type, as a four-character string. Possible attribute types are:

POIN = point,
RNGE = range,
FUNC = float functional,
INPT = integer,
LOGI = logical,
DISC = discrete,
STXT = short text,
LTXT = long text,
DTTM = date time,
HLNK = hyperlink,
PICT = picture,
FILE = file,
DSFN = discrete functional,
MAFN = maths functional (equations and logic),
TABL = tabular.

DSFN and MAFN are not supported by the MI Scripting Toolkit, and appear as UNSUPPORTED DATA TYPE.

Returns

str

AttributeDiscrete

class AttributeDiscrete(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Extended AttributeValue class for discrete attributes.

Provides access to the list of strings that store the attribute’s data values, and their display order.

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

property order

Display order of the discrete data values (strings) in MI Viewer. Order cannot be edited using the MI Scripting Toolkit.

Returns

List[int]

property is_multivalued

Whether this attribute allows multiple values to be set.

Returns

bool

property possible_discrete_values

List of the attribute’s possible discrete data values.

Returns

List[str]

property type

Attribute data type, as a four-character string. Possible attribute types are:

POIN = point,
RNGE = range,
FUNC = float functional,
INPT = integer,
LOGI = logical,
DISC = discrete,
STXT = short text,
LTXT = long text,
DTTM = date time,
HLNK = hyperlink,
PICT = picture,
FILE = file,
DSFN = discrete functional,
MAFN = maths functional (equations and logic),
TABL = tabular.

DSFN and MAFN are not supported by the MI Scripting Toolkit, and appear as UNSUPPORTED DATA TYPE.

Returns

str

AttributeFunctional

class AttributeFunctional(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Extended AttributeValue class for functional data attributes.

Stores and provides access to a data structure, parameters (constraints), specified x-axis, and individual columns and series within the functional data attribute. Series and Gridded data are stored identically in AttributeFunctional objects. However, the two data types are imported into MI differently.

The AttributeFunctional object data structure is as follows:

[[ 'y min', 'y max', 'constraint 1', 'constraint 2', 'Estimated point?'],
 [  0.0,      0.0,      'Test',         0.5,       ,      False,       ],
 [   . ,       . ,         .  ,          . ,       ,        .  ,       ],
 [   . ,       . ,         .  ,          . ,       ,        .  ,       ],
 [   . ,       . ,         .  ,          . ,       ,        .  ,       ]]

The allowed data types are float for x-y data, float, str or None for constraints, and bool for flagging whether the data point is estimated or not.

The functional data type is used to store graphical data in Granta MI. In MI Viewer there are two ways to view the data: Series and Gridded.

  • Series data is grouped according to constraints or parameters placed on x-y data. The x-axis is a constraint that is specified on import. Each group (‘Series’) can have a different linestyle.

  • Gridded data is similar to Series data, except that the x-axis is dynamically chosen within MI Viewer, and all data groups share one linestyle.

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

property value

Current value(s) of the attribute; AttributeFunctional.value always returns the current instance of the class and cannot be modified. In this case, the values of the attribute can be accessed through the AttributeFunctional.data property.

Returns

AttributeFunctional object

update_header_units()None

Updates the unit symbols in the header with the currently selected units.

Returns

None

property type

Attribute data type, as a four-character string. Possible attribute types are:

POIN = point,
RNGE = range,
FUNC = float functional,
INPT = integer,
LOGI = logical,
DISC = discrete,
STXT = short text,
LTXT = long text,
DTTM = date time,
HLNK = hyperlink,
PICT = picture,
FILE = file,
DSFN = discrete functional,
MAFN = maths functional (equations and logic),
TABL = tabular.

DSFN and MAFN are not supported by the MI Scripting Toolkit, and appear as UNSUPPORTED DATA TYPE.

Returns

str

property unit

Unit symbol for the y-axis.

Returns

str

clear()None

Deletes all data stored in the AttributeFunctional object.

Returns

None

is_empty()bool

Checks whether any of the data values in the attribute are populated.

Returns

bool

add_point(columns: Dict[str, Union[str, float, int]])None

Adds a point value to the AttributeFunctional object. Requires a dictionary with keys for the y-value, each constraint, and whether the value is estimated (optional):

  • Dictionary keys for the y-value can be either ‘y’, ‘Y’, the attribute name, or the attribute name with units.

  • Constraint keys can be either the parameter name, or the parameter name with units.

  • Constraints are optional and can either be omitted entirely or set to None.

  • The key for whether the value is estimated must be ‘Estimated?’.

Note

The Estimated? flag can currently only be set for Gridded data, not Series.

Parameters

columns – Dict[str, Union[str, float, bool, int]]

Returns

None

add_range(columns: Dict[str, Union[str, float, int]])None

Adds a range value to the AttributeFunctional object. Requires a dictionary with keys for the two y-values (ymin and ymax), each constraint, and whether the value is estimated (optional).

  • Dictionary keys for the y-value can be either ‘ymin’, ‘ymax’, or the attribute name with units and ‘Y min’ or ‘Y max’ appended.

  • Constraint keys can either be the parameter name, or the parameter name with units.

  • Constraints are optional and can either be omitted entirely or set to None.

  • The key for whether the value is estimated must be ‘Estimated?’.

Note

The Estimated? flag can currently only be set for Gridded data, not Series.

Parameters

columns – dict

Returns

None

property xaxis_parameter

ParameterDefinition for the current x-axis parameter of the functional data attribute.

Returns

ParameterDefinition object

property column_headers

Column headers with units.

Returns

List[str]

property constraint_column_index

Mapping of columns to indices for functional data attributes.

Returns

Dict[str, int]

data_by_column()Dict[str, List[Any]]

Sorts data into columns (lists of values indexed by column name). Changing a dictionary generated using this method does not affect the underlying data, and data in the dictionary will not be refreshed automatically if the underlying data changes.

Returns

Dict[str, List[Any]]

property parameters

Parameters used by the functional data attribute, indexed by name.

Returns

Dict[str, ParameterDefinition]

FunctionalSeries

class FunctionalSeries(attr_def: AttributeDefintion, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Extended AttributeFunctional class for Series functional data attributes.

Provides access to Series numbers and linestyles, and a method of generating a FunctionalGrid object from a FunctionalSeries object (generate_grid_version()).

__init__(attr_def: AttributeDefintion, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

generate_grid_version()GRANTA_MIScriptingToolkit.granta.mi_attribute_value_classes.FunctionalGrid

Creates a Gridded version of the FunctionalSeries object and returns a copy of it.

Returns

FunctionalGrid object

property data_with_series_number

Series number for all data points, returned as an additional column with the data values.

Returns

List[List[Union[str, float, bool, int]]]

property series_linestyles

Linestyles for each series (linestyle can be ‘Lines’, ‘Markers’, or ‘Both’).

Returns

Dict[int, str]

FunctionalGrid

class FunctionalGrid(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Extended AttributeFunctional class for Gridded functional data attributes.

Provides access to linestyle and a method of generating a FunctionalSeries object from a FunctionalGrid object (generate_series_version()).

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

generate_series_version()GRANTA_MIScriptingToolkit.granta.mi_attribute_value_classes.FunctionalSeries

Creates a Series version of the FunctionalGrid object and returns a copy of it.

Returns

FunctionalSeries object

property linestyle

Linestyle for gridded functional data (gridded data can only have one linestyle: ‘Lines’, ‘Markers’, or ‘Both’).

Returns

str

AttributeInteger

class AttributeInteger(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Extended AttributeValue class for integer attributes.

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

property type

Attribute data type, as a four-character string. Possible attribute types are:

POIN = point,
RNGE = range,
FUNC = float functional,
INPT = integer,
LOGI = logical,
DISC = discrete,
STXT = short text,
LTXT = long text,
DTTM = date time,
HLNK = hyperlink,
PICT = picture,
FILE = file,
DSFN = discrete functional,
MAFN = maths functional (equations and logic),
TABL = tabular.

DSFN and MAFN are not supported by the MI Scripting Toolkit, and appear as UNSUPPORTED DATA TYPE.

Returns

str

AttributeLogical

class AttributeLogical(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Extended AttributeValue class for logical attributes.

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

property type

Attribute data type, as a four-character string. Possible attribute types are:

POIN = point,
RNGE = range,
FUNC = float functional,
INPT = integer,
LOGI = logical,
DISC = discrete,
STXT = short text,
LTXT = long text,
DTTM = date time,
HLNK = hyperlink,
PICT = picture,
FILE = file,
DSFN = discrete functional,
MAFN = maths functional (equations and logic),
TABL = tabular.

DSFN and MAFN are not supported by the MI Scripting Toolkit, and appear as UNSUPPORTED DATA TYPE.

Returns

str

AttributePoint

class AttributePoint(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Extended AttributeValue class for point data attributes.

Provides access to lists of point values and their parameters. Points can be multi-valued and are represented in the Streamlined API as lists of floats. They can have multiple parameters.

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

property value

Current value of the attribute; AttributePoint.value always returns the current instance of the class and cannot be modified. In this case, the values of the attribute can be accessed through the AttributePoint.points and AttributePoint.parameters properties.

Returns

AttributePoint object

is_empty()bool

Checks whether the attribute value is populated. AttributePoint objects are empty if the length of the list AttributePoint.points == 0.

Returns

bool

property type

Attribute data type, as a four-character string. Possible attribute types are:

POIN = point,
RNGE = range,
FUNC = float functional,
INPT = integer,
LOGI = logical,
DISC = discrete,
STXT = short text,
LTXT = long text,
DTTM = date time,
HLNK = hyperlink,
PICT = picture,
FILE = file,
DSFN = discrete functional,
MAFN = maths functional (equations and logic),
TABL = tabular.

DSFN and MAFN are not supported by the MI Scripting Toolkit, and appear as UNSUPPORTED DATA TYPE.

Returns

str

property parameter_definitions

Parameter definitions for the parameters associated with the point attribute, indexed by name.

Returns

Dict[str, ParameterDefinition]

property parameters

Parameters associated with each point in the list AttributePoint.points. Each point in the list has a dictionary, indexed by parameter name and containing the parameter value for that point.

Returns

List[Dict[str, Union[float, str]]]

property points

Point values associated with this attribute.

Returns

List[float]

AttributeRange

class AttributeRange(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Extended AttributeValue class for range data attributes. Range attribute values are represented in the MI Scripting Toolkit by dictionaries of the form {'low': float, 'high': float}, and should be entered in this form when editing them.

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

property type

Attribute data type, as a four-character string. Possible attribute types are:

POIN = point,
RNGE = range,
FUNC = float functional,
INPT = integer,
LOGI = logical,
DISC = discrete,
STXT = short text,
LTXT = long text,
DTTM = date time,
HLNK = hyperlink,
PICT = picture,
FILE = file,
DSFN = discrete functional,
MAFN = maths functional (equations and logic),
TABL = tabular.

DSFN and MAFN are not supported by the MI Scripting Toolkit, and appear as UNSUPPORTED DATA TYPE.

Returns

str

AttributeTabular

class AttributeTabular(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Extended AttributeValue class for tabular data attributes.

Provides access to tabular data and its properties, such as linking attribute and table, and methods for adding, deleting or swapping rows.

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

property type

Attribute data type, as a four-character string. Possible attribute types are:

POIN = point,
RNGE = range,
FUNC = float functional,
INPT = integer,
LOGI = logical,
DISC = discrete,
STXT = short text,
LTXT = long text,
DTTM = date time,
HLNK = hyperlink,
PICT = picture,
FILE = file,
DSFN = discrete functional,
MAFN = maths functional (equations and logic),
TABL = tabular.

DSFN and MAFN are not supported by the MI Scripting Toolkit, and appear as UNSUPPORTED DATA TYPE.

Returns

str

property columns

List of columns in the tabular data.

Returns

List[str]

property linked_columns

Whether each column is linked or not.

Returns

List[bool]

property value

Current value of the attribute; AttributeTabular.value always returns the current instance of the class and cannot be modified. In this case, the values of the attribute can be accessed through the AttributeTabular.tabular property.

Returns

AttributeTabular object

property linking_table

Table object which the linking attribute belongs to. Returns None for purely local tabular data.

Returns

Table object or None

property linking_attribute

Linking attribute, a short text-type attribute used to link rows in the tabular data attribute to records. Returns None for purely local tabular data.

Returns

AttributeDefinition object or None

property data

Raw data for the attribute (list of data values per column).

Returns

List[List[Union[str, list, Picture, File, Hyperlink, float, int, tuple]]]

property units

TabularUnits object associated with this AttributeTabular object.

Returns

TabularUnits object

show()None

Displays the data as an ascii-art style table.

Returns

None

load()None

Loads linked tabular data into the class.

Returns

None

property linked_records

The records linked to each row, indexed by the linking value of each row at loading.

These links are calculated in Granta MI, and therefore cannot be edited by the user. The dictionary is unaffected by local changes to the tabular data, and the data must be re-imported to reflect local changes.

Returns

Dict[str, List[Record]]

is_empty()bool

Checks whether the attribute value is populated.

Returns

bool

property shape

Number of columns by number of rows.

Returns

Tuple[int, int]

add_row(linking_value: str = '<linking value not chosen>')None

Inserts a new unpopulated row, and sets the linking value for that row if one is provided.

Parameters

linking_value – str

Returns

None

delete_row(index: int)None

Removes the row at the specified index.

Example

delete_row(0) deletes the first row.

Parameters

index – int

Returns

None

swap_rows(row1: int, row2: int)None

Change the positions of two rows with indices row1 and row2.

Example

my_data.swap_rows(0, 4) swaps the first and fifth rows in the Tabular data structure my_data.

Parameters
  • row1 – int

  • row2 – int

Returns

None

AttributeShortText

class AttributeShortText(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Extended AttributeValue class for short text attributes.

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

property type

Attribute data type, as a four-character string. Possible attribute types are:

POIN = point,
RNGE = range,
FUNC = float functional,
INPT = integer,
LOGI = logical,
DISC = discrete,
STXT = short text,
LTXT = long text,
DTTM = date time,
HLNK = hyperlink,
PICT = picture,
FILE = file,
DSFN = discrete functional,
MAFN = maths functional (equations and logic),
TABL = tabular.

DSFN and MAFN are not supported by the MI Scripting Toolkit, and appear as UNSUPPORTED DATA TYPE.

Returns

str

AttributeLongText

class AttributeLongText(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Extended AttributeValue class for long text attributes.

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

property type

Attribute data type, as a four-character string. Possible attribute types are:

POIN = point,
RNGE = range,
FUNC = float functional,
INPT = integer,
LOGI = logical,
DISC = discrete,
STXT = short text,
LTXT = long text,
DTTM = date time,
HLNK = hyperlink,
PICT = picture,
FILE = file,
DSFN = discrete functional,
MAFN = maths functional (equations and logic),
TABL = tabular.

DSFN and MAFN are not supported by the MI Scripting Toolkit, and appear as UNSUPPORTED DATA TYPE.

Returns

str

AttributeUnsupported

class AttributeUnsupported(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)

Extended AttributeValue class for attributes with unsupported data types.

Note that unsupported attribute data will not yield any information regarding its value in that record. However, some meta-data is still available through this class (such as the attribute’s name and data type). An unsupported attribute value remains unpopulated, and these objects cannot be edited.

__init__(attr_def: AttributeDefinition, _gdl_av: GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue, _mi: Session, metas: List[GRANTA_MIScriptingToolkit.AttributeValue.AttributeValue] = None)None
Parameters
Returns

None

property is_applicable

Whether the attribute is applicable to the current record. Setting this to False will clear any data values on the attribute.

Returns

bool

is_empty()bool

Checks whether the attribute value is populated.

Returns

bool

property type

Attribute data type, as a four-character string. Possible attribute types are:

POIN = point,
RNGE = range,
FUNC = float functional,
INPT = integer,
LOGI = logical,
DISC = discrete,
STXT = short text,
LTXT = long text,
DTTM = date time,
HLNK = hyperlink,
PICT = picture,
FILE = file,
DSFN = discrete functional,
MAFN = maths functional (equations and logic),
TABL = tabular.

DSFN and MAFN are not supported by the MI Scripting Toolkit, and appear as UNSUPPORTED DATA TYPE.

Returns

str

PseudoAttributeValue

class PseudoAttributeValue(name: str)

Stores and provides access to pseudo-attribute data values.

__init__(name: str)None
Parameters

name – str

Returns

None

property value

Current value of the pseudo-attribute. Cannot be modified. Modification of pseudo-attributes must be done through the Record object properties color, short_name and name.

Returns

Union[List[str], str, int, bool, Set[str], datetime.datetime]

property id

Attribute identifier (this is always 0 for pseudo-attributes).

Returns

int

is_empty()bool

Checks whether the pseudo-attribute value is populated or not.

Returns

bool

property name

Name of the pseudo-attribute.

Returns

str

property type

Data type of the pseudo-attribute value (four-character string).

Returns

str

Sub-attribute level

Classes that are used by attribute objects but are not attributes themselves.

ParameterDefinition

class ParameterDefinition(_gdl_param: GRANTA_MIScriptingToolkit.ParameterDetail.ParameterDetail, _mi: Session, unit_conversions: Dict[str, str] = None)
__init__(_gdl_param: GRANTA_MIScriptingToolkit.ParameterDetail.ParameterDetail, _mi: Session, unit_conversions: Dict[str, str] = None)None

Streamlined API wrapper for the Foundation API GRANTA_MIScriptingToolkit.ParameterDetail class. Provides access to parameter properties such as revision history, default and possible values, and units.

Note

Do not create new instances of this class; it represents a pre-existing database structure.

Parameters
Returns

None

property value_for_exporters

Value on the ParameterDefinition instance for use in any exporters the parameter is passed to. Can be set by the user.

Returns

Union[str, float]

property name

Parameter name.

Returns

str

property parent_attribute

Name of the parent attribute.

Returns

str

property parent_record

Long name of the parent record.

Returns

str

property history

Revision history of the parameter, as an ObjectHistory object.

Returns

ObjectHistory object

property default_value

Default value of the parameter (all parameters must have a default value).

Returns

str or float

property history_of_default

Revision history of the parameter’s default value, as an ObjectHistory object.

Returns

ObjectHistory object

property interpolation_type

The interpolation type for the parameter (‘None’, ‘Linear’, or ‘Cubic Spline’).

Returns

str

property order

Order in which the parameter is stored in the attribute (column number). This is relevant for some interpolation methods, and determines the display order in MI Viewer.

Returns

int

property axis_scale_type

Axis scale type for the parameter (‘Linear’ or ‘Logarithmic’).

Returns

str

property unit

Unit symbol for the parameter.

Returns

str

reset_unit()None

Resets the unit back to its original value (the unit in use when the parameter was initially exported). Does not make a call to the Service Layer.

Returns

None

property values

List of all possible values the parameter can take.

Returns

List[Union[str, float]]

property values_histories

Revision histories of each possible value of a parameter, as a list of ObjectHistory objects.

Returns

List[ObjectHistory]

property type

Parameter type (‘Unrestricted’ numeric, ‘Restricted’ numeric, or ‘Discrete’).

Returns

str

property id

Parameter identifier.

Returns

int

ObjectHistory

class ObjectHistory(_gdl_revision_info: GRANTA_MIScriptingToolkit.RevisionInfo.RevisionInfo)

Provides access to the revision history of an MI database element. Most structures, values and items have recorded histories in MI, for example tabular columns and functional data parameter values.

Note

Do not create new instances of this class; it represents a pre-existing database structure.

__init__(_gdl_revision_info: GRANTA_MIScriptingToolkit.RevisionInfo.RevisionInfo)None
Parameters

_gdl_revision_info – Foundation API GRANTA_MIScriptingToolkit.RevisionInfo class

Returns

None

property last_modified_date

Date the database element was last modified.

Returns

str

property date_created

Date the database element was created.

Returns

str

property last_modified_by

The username of the last user to modify the database element.

Returns

str

property created_by

The username of the user who created the database element.

Returns

str

SearchCriterion

class SearchCriterion(attribute: Union[AttributeDefinition], operator: str, value: Union[float, int, str, List[str], Tuple[Union[str, datetime.datetime], Union[str, datetime.datetime]], List[float]] = None, column_name: str = None)

Defines a single criterion for use in a search. The criterion can be as simple as the presence of the specified attribute, or as complex as the data in a specified column of the tabular attribute being greater than a specifed value. The search will use the same units as the AttributeDefinition.

__init__(attribute: Union[AttributeDefinition], operator: str, value: Union[float, int, str, List[str], Tuple[Union[str, datetime.datetime], Union[str, datetime.datetime]], List[float]] = None, column_name: str = None)None
Parameters
Returns

None

property attribute

AttributeDefinition for the attribute used in this search criterion.

Returns

AttributeDefinition object

property operation

Operator used in this criterion, if provided.

Example

‘EXISTS’ or ‘CONTAINS’

Returns

str

BinaryType

class BinaryType

Stores and provides access to Pictures and Files, and associated metadata. Pictures and files can appear in Granta MI as data (for example, in a tabular data column), or as an attribute value.

The BinaryType object wraps files and images for inclusion in the corresponding MI Scripting Toolkit classes.

__init__()None
Returns

None

property value

Current value of the attribute; BinaryType.value always returns the current instance of the class and cannot be modified. In this case, the values are the file or picture, which can be accessed through the load and save methods of the File or Picture classes.

Returns

BinaryType object

property url

URL used to access the file. Returns None if the URL is unpopulated, or the file has not been imported yet.

Returns

str or None

property mime_file_type

MIME (Multipurpose Internet Mail Extensions) file type, if populated.

Some commonly-used extensions are:

image/png - .png
image/gif - .gif
image/bmp - .bmp
image/tiff - .tif, .tiff
text/plain - .txt
application/zip - .zip
application/pdf - .pdf
application/vnd.ms-excel - .xls
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet - .xlsx
application/vnd.ms-powerpoint - .ppt
application/vnd.openxmlformats-officedocument.presentationml.presentation - .pptx
application/msword - .doc
application/vnd.openxmlformats-officedocument.wordprocessingml.document - .docx
Returns

str

is_empty()bool

Checks whether the BinaryType object is populated by checking whether there is binary data in the object.

Returns

bool

Picture

class Picture(name: Optional[str] = None, path: Optional[Union[str, pathlib.Path]] = None, load: bool = True)

Extended BinaryType class for Pictures in MI.

Provides access to image data through save/load methods. When the path to the image file is specified and load is True, the Picture object is populated automatically.

In Granta MI, Pictures do not have file names, and are instead stored as binary data that can be accessed by viewing the image in an MI application.

__init__(name: Optional[str] = None, path: Optional[Union[str, pathlib.Path]] = None, load: bool = True)None
Parameters
  • name – str (Picture name, used for locally saving and loading)

  • path

    Union[str, pathlib.Path] (Path to the image file to be imported. Takes the form C:\Users\yourname\Pictures\image.jpg or /home/username/Pictures/image.jpg

    Deprecated: Path to the folder containing the file to be imported. Takes the form C:\Users\yourname\Pictures\ or /home/username/Pictures/)

  • load – bool

Returns

None

load(path: Union[str, pathlib.Path], file_name: Optional[str] = None)None

Populates the Picture object with the image file_name located on path. Relative paths accepted.

Parameters
  • path

    Union[str, pathlib.Path] (Path to the image file to be imported. Takes the form C:\Users\yourname\Pictures\image.jpg or /home/username/Pictures/image.jpg

    Deprecated: Path to the folder containing the file to be imported. Takes the form C:\Users\yourname\Pictures\ or /home/username/Pictures/)

  • file_name – str (Image file name, with file extension)

Returns

None

save(path: Union[str, pathlib.Path], file_name: Optional[str] = None)None

Saves a Picture object to file location path. Relative paths accepted.

Deprecated: Saves a Picture object to folder location path with name file_name. If file_name is not specified, the extension will be inferred from the mime_type and the image filename will be <attribute name>.extension.

Parameters
  • path

    Union[str, pathlib.Path] (Path where the image should be saved. Takes the form C:\Users\yourname\Pictures\image.jpg or /home/username/Pictures/image.jpg

    Deprecated: Path to the folder where the image should be saved. Requires separate file_name parameter. Takes the form C:\Users\yourname\Pictures\ or /home/username/Pictures/)

  • file_name – str (Image file name, with file extension)

Returns

None

property binary_data

The binary data for the image. Binary data can be set with a bytes object or file buffer.

Returns

bytes or None.

File

class File(file_name: Optional[str] = None, path: Optional[Union[str, pathlib.Path]] = None, load: bool = True)

Extended BinaryType class for Files in MI.

Stores and provides access to file names and descriptions displayed in MI applications.

  • file_name must be defined on creation of the File object

  • description defaults to the file_name on creation, but can be edited afterwards

When path is specified and load is True, the file is loaded automatically into the File object. If load is False, no path will be stored even if one is specified.

__init__(file_name: Optional[str] = None, path: Optional[Union[str, pathlib.Path]] = None, load: bool = True)None
Parameters
  • file_name – str

  • path

    Union[str, pathlib.Path] (Path to the file to be imported. Takes the form C:\Users\yourname\Documents\file.pdf or /home/username/Documents/file.pdf

    Deprecated: Path to the folder containing the file to be imported. Takes the form C:\Users\yourname\Documents\ or /home/username/Documents/)

  • load – bool

Returns

None

save(path: Optional[Union[str, pathlib.Path]] = None, file_name: Optional[str] = None)None

Saves a File object to file location path. Relative paths accepted.

Deprecated: Saves a File object to folder location path with name file_name. If file_name is not specified, the file will be saved as <attribute name>, without an extension.

Parameters
  • path

    Union[str, pathlib.Path] (Path where the file should be saved. Takes the form C:\Users\yourname\Documents\file.pdf or /home/username/Documents/file.pdf

    Deprecated: Path to the folder where the file should be saved. Requires separate file_name parameter. Takes the form C:\Users\yourname\Documents\ or /home/username/Documents/)

  • file_name – str (Deprecated: File name, with extension)

Returns

None

load(path: Optional[Union[str, pathlib.Path]] = None, file_name: Optional[str] = None)None

Populates the File object with the file located by path. Relative paths accepted.

Deprecated: Populates the File object with the file named file_name at location path.

Parameters
  • path

    Union[str, pathlib.Path] (Path to the file to be imported. Takes the form C:\Users\yourname\Documents\file.pdf or /home/username/Documents/file.pdf

    Deprecated: Path to the folder containing the file to be imported. Takes the form C:\Users\yourname\Documents\ or /home/username/Documents/)

  • file_name – str (File name, with extension)

Returns

None

property file_name

Name of the file.

Returns

str

property binary_data

The binary data for the file. Binary data can be set with a bytes object or file buffer.

Returns

bytes or None.

TabularUnits

class TabularUnits(units: List[List[str]], default_units: List[str])

Stores and provides access to the units for a parent AttributeTabular object, in the same tabular format as the data.

Units can be set on a cell-by-cell basis. TabularUnits is populated when the parent AttributeTabular object is loaded.

Any changes made to the underlying AttributeTabular.data() property must also be made to the corresponding TabularUnits.data() and vice versa, or your changes will not import successfully and may be lost (AttributeTabular.add_row() and AttributeTabular.delete_row() make the necessary changes to both objects, but you must duplicate other changes to data yourself).

__init__(units: List[List[str]], default_units: List[str])None
Parameters
  • units – List[List[str]]

  • default_units – List[str]

Returns

None

property database_units

The default units, as a list corresponding to each column.

Returns

List[str]

property data

Data values (unit symbol strings) stored in the TabularUnits object.

Returns

List[List[str]]

Asynchronous Job Queue

These classes allow users to interact with the MI Asynchronous Job Queue, submitting Excel and Text importer jobs and monitoring their progress. This functionality relies on the external library requests.

AsyncJobQueue

class AsyncJobQueue(mi_session: Session, queue_url: str = None, verify_ssl: bool = True, ssl_ca_bundle: Union[str, pathlib.Path] = None)
__init__(mi_session: Session, queue_url: str = None, verify_ssl: bool = True, ssl_ca_bundle: Union[str, pathlib.Path] = None)None

Represents an instance of the Async Job Queue manager. Allows management of the job queue and submission of jobs.

Parameters
  • mi_sessionSession object

  • queue_url – str (Job queue URL, if different from Service Layer URL; extracted from mi_session if not specified)

  • verify_ssl – bool (Whether to verify SSL connections to remote server, True by default)

  • ssl_ca_bundle – Union[str, pathlib.Path] (optional) (Path to custom CA bundle (.crt or .pem); use if your MI installation has a self-signed certificate which is not trusted by the requests module)

property processing_configuration

Gets the current job queue configuration information from the server.

Returns

dict

property is_admin_user
Checks whether the current user is a Job Queue admin (returns True if the user is an admin). Admin users can

promote jobs to the top of the queue and interact with other users’ jobs.

Returns

bool

property can_write_job

Checks whether the current user can create new jobs (returns True if they can).

Returns

bool

property num_jobs

Returns the number of jobs in the Job Queue, including completed and failed jobs.

Returns

int

property jobs

Returns a list of all jobs visible on the server. Running or pending jobs are sorted according to their position in the queue, completed or failed jobs are returned last.

Returns

List[AsyncJob]

jobs_where(name: Optional[str] = None, type_: Optional[str] = None, description: Optional[str] = None, submitter_name: Optional[str] = None, status: Optional[str] = None)List[GRANTA_MIScriptingToolkit.granta.mi_async_jobs.AsyncJob]

Returns a list of jobs on the server matching a query. Running or queued jobs are sorted according to their position in the queue, completed or failed jobs are returned last.

Parameters
  • name – str (Job name must contain)

  • type – str (DataImportJob, TextImportJob, ExcelImportJob, ExcelExportJob)

  • description – str (Job description must contain)

  • submitter_name – str (Name of user who submitted the job must equal)

  • status – str (Pending, Running, Succeeded, Failed, Cancelled, Corrupted)

Returns

List[AsyncJob]

get_job_by_id(job_id: str)GRANTA_MIScriptingToolkit.granta.mi_async_jobs.AsyncJob

Gets the job with unique identifier job_id from the server.

Parameters

job_id – str

Returns

AsyncJob object

delete_jobs(jobs: List[GRANTA_MIScriptingToolkit.granta.mi_async_jobs.AsyncJob])None

Deletes jobs from the server.

Parameters

jobs – List[AsyncJob]

Returns

None

create_import_job_and_wait(job_request: GRANTA_MIScriptingToolkit.granta.mi_async_jobs.ImportJobRequest)GRANTA_MIScriptingToolkit.granta.mi_async_jobs.AsyncJob

Creates an import job from an ImportJobRequest object. Uploads files and submits a job request to the Job Queue. Blocks execution until the job has either completed or failed, then returns the finished AsyncJob object.

Parameters

job_requestImportJobRequest object

Returns

AsyncJob object

create_import_job(job_request: GRANTA_MIScriptingToolkit.granta.mi_async_jobs.ImportJobRequest)GRANTA_MIScriptingToolkit.granta.mi_async_jobs.AsyncJob

Creates an import job from an ImportJobRequest object. Uploads files and submits a job request to the Job Queue, then returns an in-progress AsyncJob object for later use.

Parameters

job_requestImportJobRequest object

Returns

AsyncJob object

ImportJobRequest

class ImportJobRequest(name: str, description: str, scheduled_execution_date: Optional[datetime.datetime] = None)

Abstract base class representing an import job request. Each subclass represents a specific import type and may override some steps of the import process. They also add additional file types and properties as required.

abstract __init__(name: str, description: str, scheduled_execution_date: Optional[datetime.datetime] = None)None
Parameters
  • name – str (Display name of the job)

  • description – str

  • scheduled_execution_date – datetime.datetime (Earliest date and time job should be executed)

Returns

None

get_job_for_import()GRANTA_MIScriptingToolkit.granta.AsyncJobs.models.job_request.JobRequest

Creates a JobRequest object ready for import. Should be called after uploading files to the service.

Returns

JobRequest object

abstract check_valid_for_import()None

Verifies that the import job can run. Raises a ValueError with a specific error message if not enough files have been provided for the import to successfully complete.

Returns

None

ExcelImportJobRequest

class ExcelImportJobRequest(name: str, description: str, scheduled_execution_date: Optional[datetime.datetime] = None, data_files: Optional[List[Union[str, pathlib.Path, IO]]] = None, template_files: Optional[List[Union[str, pathlib.Path, IO]]] = None, combined_files: Optional[List[Union[str, pathlib.Path, IO]]] = None, attachment_files: Optional[List[Union[str, pathlib.Path, IO]]] = None)

Represents an Excel import job request. Supports either combined imports (with template and data in the same file), or separate data and template imports.

__init__(name: str, description: str, scheduled_execution_date: Optional[datetime.datetime] = None, data_files: Optional[List[Union[str, pathlib.Path, IO]]] = None, template_files: Optional[List[Union[str, pathlib.Path, IO]]] = None, combined_files: Optional[List[Union[str, pathlib.Path, IO]]] = None, attachment_files: Optional[List[Union[str, pathlib.Path, IO]]] = None)
Parameters
  • name – str (Display name of the job)

  • description – str

  • scheduled_execution_date – datetime.datetime (Earliest date and time job should be executed)

  • data_files – List[Union[str, pathlib.Path, IO]] (Excel files containing data)

  • template_files – List[Union[str, pathlib.Path, IO]] (Excel template files)

  • combined_files – List[Union[str, pathlib.Path, IO]] (Excel files containing both template and data)

  • attachment_files – List[Union[str, pathlib.Path, IO]] (Any other files referenced in data or combined Excel files)

check_valid_for_import()

Verifies that the import job can run. Raises a ValueError with a specific error message if not enough files have been provided for the import to successfully complete.

Returns

None

TextImportJobRequest

class TextImportJobRequest(name: str, description: str, scheduled_execution_date: Optional[datetime.datetime] = None, data_files: Optional[List[Union[str, pathlib.Path, IO]]] = None, template_files: Optional[List[Union[str, pathlib.Path, IO]]] = None, attachment_files: Optional[List[Union[str, pathlib.Path, IO]]] = None)

Represents a Text import job request. Requires a template file and one or more data files.

__init__(name: str, description: str, scheduled_execution_date: Optional[datetime.datetime] = None, data_files: Optional[List[Union[str, pathlib.Path, IO]]] = None, template_files: Optional[List[Union[str, pathlib.Path, IO]]] = None, attachment_files: Optional[List[Union[str, pathlib.Path, IO]]] = None)
Parameters
  • name – str (Display name of the job)

  • description – str

  • scheduled_execution_date – datetime.datetime (Earliest date and time job should be executed)

  • data_files – List[Union[str, pathlib.Path, IO]] (Text files containing data)

  • template_files – List[Union[str, pathlib.Path, IO]] (Text importer template file)

  • attachment_files – List[Union[str, pathlib.Path, IO]] (Any other files referenced in data files)

check_valid_for_import()

Verifies that the import job can run. Raises a ValueError with a specific error message if not enough files have been provided for the import to successfully complete.

Returns

None

AsyncJob

class AsyncJob
property id

Unique job identifier in GUID form. Recommended way to refer to individual jobs.

Returns

str

property name

Display name of the job (not unique).

Returns

str

update_name(value: str)None

Updates the display name of the job on the server.

Parameters

value – str

Returns

None

property description

Description of the job (displayed in MI).

Returns

str

update_description(value: str)None

Updates the job description on the server.

Parameters

value – str

Returns

None

property status

Job status on the server:

  • Pending: Job is in the queue

  • Running: Job is currently executing

  • Succeeded: Job has completed (does not guarantee that no errors occurred)

  • Failed: Job could not complete

  • Cancelled: Job was cancelled by the user

  • Corrupted: Something went wrong on the server

If the job associated with the AsyncJob object was deleted, returns Deleted.

Returns

str

property type

Job type, as known to the server.

Returns

str

property position

Position in the Job Queue. Returns an int if the job is pending, otherwise returns None.

Returns

int or None

move_to_top()None

Promotes the job to the top of the Job Queue. User must have MI_ADMIN permission.

Returns

None

property submitter_information

Information about the job submission. Returns the username of the submitter, date_time of submission, and the roles to which the submitter belongs as a dictionary indexed by name.

Returns

dict

property completion_date_time

Date and time of job completion. Returns None if job is pending.

Returns

datetime.datetime or None

property execution_date_time

Date and time of job execution. Returns None if job is pending.

Returns

datetime.datetime or None

property scheduled_execution_date_time

Date and time of job execution, if scheduled.

Returns

datetime.datetime or None

update_scheduled_execution_date_time(value: datetime.datetime)None

Updates the scheduled execution time on the server.

Parameters

value – datetime.datetime

Returns

None

property output_information

Provides additional information such as record placement or verbose logging, if the job type supports it.

Returns

Any job-specific outputs

property output_file_names

List of file names produced by the job, for example log files.

Returns

List[str]

download_file(remote_file_name: str, file_path: Union[str, pathlib.Path])None

Downloads an output file from the server by name and saves it to a specified location.

Parameters
  • remote_file_name – str (File name provided by output_file_names())

  • file_pathpathlib.Path or str (Path where the file should be saved; if a file name isn’t specified, the name provided by output_file_names() is used)

Returns

None

get_file_content(remote_file_name: str)Union[bytes, str, dict]

Downloads an output file from the server by name, and returns the file contents.

Parameters

remote_file_name – str (File name provided by output_file_names())

Returns

Union[bytes, str, dict]

update()None

Updates the job from the server.

Returns

None

Helper Functions

connect

connect(service_layer_url: str, user_name: str = None, password: str = None, domain: str = None, autologon: bool = None, timeout: int = 300000, existing_session: GRANTA_MIScriptingToolkit.GRANTA_MISession.GRANTA_MISession = None, oidc: bool = False, auth_token: str = None, refresh_token: str = None, use_stored_token: bool = False)Session

Establishes a connection to the Granta MI server and returns a Session object.

An existing session may be specified.

Parameters
  • service_layer_url – str

  • user_name – str

  • password – str

  • domain – str

  • autologon – bool

  • timeout – int (maximum time to wait for a response, in milliseconds)

  • existing_session – Foundation API GRANTA_MIScriptingToolkit.GRANTA_MISession class

  • oidc – bool

  • auth_token – str

  • refresh_token – str

  • use_stored_token – bool

Returns

Session object

extract_parameter_value

extract_parameter_value(param_value: GRANTA_MIScriptingToolkit.ParameterValue.ParameterValue)Union[float, str]

Returns the data value stored in a Foundation API GRANTA_MIScriptingToolkit.ParameterValue object.

Parameters

param_value – Foundation API GRANTA_MIScriptingToolkit.ParameterValue class

Returns

str or float

get_foundation_logger

get_foundation_logger()logging.Logger

Return the logger used by the Foundation API (has the name “GDL”).

Returns

Logger class

log_to_file_in_local_app_data

log_to_file_in_local_app_data(path='Granta Design\\MIScriptingToolkit\\Python')None

Set up the built-in Granta logger to log to a file in the user’s local app data directory (%LOCALAPPDATA% on Windows, ‘~/.appdata/’ on Linux). The log file name is MIScriptingToolkitForPython_YYYY.MM.DD.log and you can specify the filepath. The default filepath is Granta Design/MIScriptingToolkit/Python.

Parameters

path – str

Returns

None