Skip to main content
This example demonstrates how to use the Granta MI RecordLists library with the Scripting Toolkit. The RecordLists library provides programmatic access to the Favorites feature in Granta MI, which allows users to create and access lists of records stored on the Granta MI server. The example demonstrates two use scenarios:
  1. Create a record list and add Streamlined API Record objects to it.
  2. Fetch a record list and create Streamlined API Record objects from the contents.
These use cases are then repeated to show how similar steps are performed for version-controlled records. This example does not cover all aspects of the RecordLists package. Full API documentation and additional examples are available here.
Info:Running this notebook requires the ansys-grantami-recordlists package. See the ‘PyGranta Dependencies’ section of the ‘Example Notebooks’ documentation page for more details.

Create a record list from Streamlined API Record objects

First create an MI Scripting Toolkit session.

Create a list of Streamlined API Record objects

Search for all MaterialUniverse records with a density above a certain threshold. The Table.search_for_records_where method returns a list of Streamlined API Record objects.
Previous cell output:

Create an ‘ansys-grantami-recordlists’ client

Use the Connection class to connect to create Record List client.
Previous cell output:

Add Streamlined API Record objects to a Record List

A RecordList object is a collection of RecordListItem objects, where each RecordListItem refers to a specific Granta MI record. Therefore, to add records to a RecordList, we must first create a list of RecordListItem objects from Streamlined API Record objects.
Now, use the RecordList.add_items_to_list method to add the RecordListItem objects to the RecordList. This method returns all items now contained in the RecordList.
Previous cell output:

Get Streamlined API Record objects from a Record List

The method RecordList.add_items_to_list called above returned the list of RecordListItem objects, and so the following cell is not strictly necessary. However, for completeness, the following cell identifies a RecordList by name and gets the contents of the list.
Previous cell output:
Use the Session.get_records_by_ids method to instantiate multiple Record objects at once. This method requires database keys, but the RecordListItem objects only contain database GUIDs. To convert between the two:
  1. Use the Session.dbs_by_guid dictionary to get the Database object given its GUID
  2. Access the Database.db_key property to get the database key.
Warning:It is a valid Granta MI configuration to have multiple databases with the same GUID. In this situation, Session.dbs_by_guid will raise a KeyError. In this case, use Session.get_db() and provide additional arguments to identify a single database, for example the database name.
Previous cell output:

Version-controlled records

Create a record list from version-controlled Streamlined API Record objects

Search for all Design Data records with a density above a certain threshold.
Since the Design Data table is version-controlled, each Record object represents a particular version of a Granta MI record. This can be seen by accessing the version_number property.
Previous cell output:
When creating a RecordListItem that represents a version-controlled record, the record_version parameter is optional. If it is specified, the RecordListItem represents that specific version. If it is omitted, the RecordListItem tracks the latest available version of that record. In this example, provide the version number of the latest version.
Previous cell output:

Get Streamlined API Record objects from a Record List with version-controlled items

As in the non-versioned example, use the Session.get_records_by_ids method to instantiate the Record objects. In this case though, we provide both the hguid and vguid parameters for each record:
  • The hguid (or record history GUID) refers to all versions of a record, and generally resolves to the latest available version that the user can access.
  • The vguid (record version GUID or record GUID) refers to a specific version of a record.
If a record_version was provided when creating a RecordListItem, the RecordListItem.record_guid property will be populated. If however, the RecordListItem was created without a record_version, the RecordListItem.record_guid property will be empty. In both cases the record_history_guid is populated. Since the Session.get_records_by_ids prioritizes the vguid parameter over the hguid parameter, we can provide both:
  • If the RecordListItem.record_guid property exists, Session.get_records_by_ids will resolve the specific version of the record.
  • If the RecordListItem.record_guid property does not exist, Session.get_records_by_ids will identify the latest available version for the user.
The following code therefore correctly identifies items specified both with and without a version.
Previous cell output: