Connect to MI
Import thegranta 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.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
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)
my_db = mi.get_db(db_key="MI_Training")
my_db.unit_system = 'UK Imperial'
my_db.absolute_temperatures = False
my_table = my_db.get_table("MaterialUniverse")
print(f"Table {my_table.name} has {len(my_table.attributes)} attributes defined")
Table MaterialUniverse has 424 attributes defined
print(f"The definition of the Density attribute in {my_table.name} is {my_table.attributes['Density']}")
The definition of the Density attribute in MaterialUniverse is <Attribute Definition, name: Density, type: RNGE, unit: lb/in^3>
print("Finding Aluminum, 7075, wrought, T73...")
my_record = my_table.search_for_records_by_name("Aluminum, 7075, wrought, T73")[0]
Finding Aluminum, 7075, wrought, T73...
print("Found this record:")
my_record
Found this record:
<Record long name: Aluminum, 7075, wrought, T73>
print("in database/table:")
f"{my_record.db_key}/{my_record.table_name}"
in database/table:
'MI_Training/MaterialUniverse'
print("at this point in the tree:")
" => ".join(my_record.path)
at this point in the tree:
'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)"]
with data like this:
<RangeValue name: Mg (magnesium), value: {'low': 2.5, 'high': 2.5}, high_value_is_inclusive: True, low_value_is_inclusive: True, unit: %>
print("and you can see it in MI Viewer here:")
my_record.viewer_url
and you can see it in MI Viewer here:
'http://my.server.name/mi/datasheet.aspx?dbKey=MI_Training&recordHistoryGuid=7682acfe-46ca-4adf-94f7-6fa678debed1'
Was this page helpful?