Get Started
Last update: 16.07.2025Load MI Scripting Toolkit, connect to your MI Session, and select a database and table.
Connect to MI
Import the granta libraries and connect to Granta MI via the Service Layer using Windows authentication,
replacing my.server.name with the name of your Granta MI server.
from GRANTA_MIScriptingToolkit import granta as mpy
mi = mpy.connect("http://my.server.name/mi_servicelayer", autologon=True)
Select a database
All the sample scripts use the MI Training database.
my_db = mi.get_db(db_key="MI_Training")
Set a unit system, and choose whether to use absolute or relative temperatures (Kelvin/Rankine or Celsius/Fahrenheit).
my_db.unit_system = 'UK Imperial'
my_db.absolute_temperatures = False
Select a table
Select MaterialUniverse and print its number of attributes.
my_table = my_db.get_table("MaterialUniverse")
print(f"Table {my_table.name} has {len(my_table.attributes)} attributes defined")
Previous cell output:
Table MaterialUniverse has 424 attributes defined
Print the definition of an attribute within your table.
print(f"The definition of the Density attribute in {my_table.name} is {my_table.attributes['Density']}")
Previous cell output:
The definition of the Density attribute in MaterialUniverse is <attribute name: type: unit: lb>
Find a record
Search for a record by name (only exact matches for short or long name will be returned), and print information to help you locate and view it in MI applications.
print("Finding Aluminum, 7075, wrought, T73...")
my_record = my_table.search_for_records_by_name("Aluminum, 7075, wrought, T73")[0]
Previous cell output:
Finding Aluminum, 7075, wrought, T73...
print("Found this record:")
my_record
Previous cell output:
Found this record:
Previous cell output:
<record long name: t73>
print("in database/table:")
f"{my_record.db_key}/{my_record.table_name}"
Previous cell output:
in database/table:
Previous cell output:
'MI_Training/MaterialUniverse'
print("at this point in the tree:")
" => ".join(my_record.path)
Previous cell output:
at this point in the tree:
Previous cell output:
'Metals and alloys => Non-ferrous => Aluminum => Wrought => 7000 series (Zn-alloyed) => 7075'
print("with data like this:")
my_table.bulk_fetch([my_record], attributes=["Mg (magnesium)"])
my_record.attributes["Mg (magnesium)"]
Previous cell output:
with data like this:
Previous cell output:
<rangevalue name: mg value: high_value_is_inclusive: low_value_is_inclusive: unit:>
print("and you can see it in MI Viewer here:")
my_record.viewer_url
Previous cell output:
and you can see it in MI Viewer here:
Previous cell output:
'http://my.server.name/mi/datasheet.aspx?dbKey=MI_Training&recordHistoryGuid=7682acfe-46ca-4adf-94f7-6fa678debed1'