- Create a record list and add Streamlined API
Recordobjects to it. - Fetch a record list and create Streamlined API
Recordobjects from the contents.
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
Table.search_for_records_where method returns a list of Streamlined API Record objects.
Create an ‘ansys-grantami-recordlists’ client
Use theConnection class to connect to create Record List client.
Add Streamlined API Record objects to a Record List
ARecordList 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.
RecordList.add_items_to_list method to add the RecordListItem objects to the
RecordList. This method returns all items now contained in the RecordList.
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.
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:
- Use the
Session.dbs_by_guiddictionary to get theDatabaseobject given its GUID - Access the
Database.db_keyproperty 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.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.
Record object represents a particular
version of a Granta MI record. This can be seen by accessing the version_number
property.
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.
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.
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_guidproperty exists,Session.get_records_by_idswill resolve the specific version of the record. - If the
RecordListItem.record_guidproperty does not exist,Session.get_records_by_idswill identify the latest available version for the user.