Skip to main content

Granta MI Scripting Toolkit 4.2

Create and Delete Records in Bulk

Last update: 16.07.2025

Create records and delete (or withdraw) them in bulk.

Specify a table

from datetime import datetime
from GRANTA_MIScriptingToolkit import granta as mpy

mi = mpy.connect("http://my.server.name/mi_servicelayer", autologon=True)
table = mi.get_db(db_key="MI_Training").get_table("Files for Training")

Create records

Decide which folder the new records will be added to (you can use the table itself as a parent for a 'top-level' record).

parent = table.search_for_records_by_name("Other")[0]

Create five new Record objects.

now = datetime.now().strftime("%c")
recordNames = [f"Scripting Toolkit Example 6:{now} - {i}" for i in range(5)]
new_records = [table.create_record(n, parent=parent, subsets={"All files"}) for n in recordNames]
new_records

Previous cell output:

[<record long name: scripting toolkit example may>,
 <record long name: scripting toolkit example may>,
 <record long name: scripting toolkit example may>,
 <record long name: scripting toolkit example may>,
 <record long name: scripting toolkit example may>]

Write your changes to MI

The new records are created on the server when update() is called.

recs = mi.update(new_records)

print("New records:")
for rec in recs:
    print(rec.viewer_url)

Previous cell output:

New records:
http://my.server.name/mi/datasheet.aspx?dbKey=MI_Training&amp;recordHistoryGuid=975bc163-8df2-4cd6-9421-9cf7ef83e8c9
http://my.server.name/mi/datasheet.aspx?dbKey=MI_Training&amp;recordHistoryGuid=e1abe509-f1b5-4a6a-9e3a-f6d2e9e7e5c8
http://my.server.name/mi/datasheet.aspx?dbKey=MI_Training&amp;recordHistoryGuid=65394190-e659-4950-99fd-df33af02e430
http://my.server.name/mi/datasheet.aspx?dbKey=MI_Training&amp;recordHistoryGuid=22bd9edf-6a76-417a-81a8-aee6dfdcaf6a
http://my.server.name/mi/datasheet.aspx?dbKey=MI_Training&amp;recordHistoryGuid=f9bbed4d-f9ce-4df8-be58-27eed426118a

Delete the records

Session.bulk_delete_or_withdraw_records accepts any list of records (e.g. results of a search, Table.all_records(), Record.children, etc.). If the table is version-controlled, the records are withdrawn instead. Unlike record creation, this method interacts directly with the server. The records are deleted or withdrawn when the method is called.

mi.bulk_delete_or_withdraw_records(recs)

Connect with Ansys