GetUnitConversions
Last update: 16.07.2025Export the Young's Modulus in the Metric system for a record
import pandas
import GRANTA_MIScriptingToolkit as gdl
session = gdl.GRANTA_MISession("http://my.server.name/mi_servicelayer/", autoLogon=True, receiveTimeout=5000)
db_key = "MI_Training"
table_name = "Tensile Test Data"
import_service = session.dataImportService
browse_service = session.browseService
export_service = session.dataExportService
partial_table_ref = gdl.PartialTableReference(tableName=table_name)
modfied_record_guid = "4269f1bc-df6b-4a6d-870c-ef931728f37b"
modified_record_ref = gdl.RecordReference(DBKey=db_key, recordGUID=modfied_record_guid)
attribute_name = "Young's Modulus (11-axis)"
unit_context_metric = gdl.UnitConversionContext(unitSystem="Metric")
modulus_attribute_ref = gdl.AttributeReference(
name=attribute_name,
DBKey=db_key,
partialTableReference=partial_table_ref,
)
export_request = gdl.GetRecordAttributesByRefRequest(
recordReferences=[modified_record_ref],
attributeReferences=[modulus_attribute_ref],
)
exported_data = export_service.GetRecordAttributesByRef(export_request).recordData
modulus_value = [[a.pointDataType.points[0].value for a in r.attributeValues] for r in exported_data][0][0]
modulus_metric_symbol = [[a.pointDataType.unitSymbol for a in r.attributeValues] for r in exported_data][0][0]
print(f"Young's modulus = {modulus_value} {modulus_metric_symbol}")
Previous cell output:
Young's modulus = 174.0004272460938 GPa
Now let's convert its value with all available conversions in Granta MI
unit_conversions_request = gdl.GetUnitConversionsRequest(
DBKey=db_key,
unitSymbols=[modulus_metric_symbol],
)
source_units = browse_service.GetUnitConversions(unit_conversions_request).sourceUnits
conversion_targets = [c.conversions for c in source_units]
factors_and_offsets = [[(c.factor, c.offset) for c in c_target] for c_target in conversion_targets][0]
symbols = [[c.targetSymbol for c in c_target] for c_target in conversion_targets][0]
results = [modulus_value * factor + offset for factor, offset in factors_and_offsets]
equations = [f"{modulus_value} * {factor} + {offset}" for factor, offset in factors_and_offsets]
factors, offsets = zip(*factors_and_offsets)
df = pandas.DataFrame([factors, offsets, equations, results])
df_flipped = df.transpose()
df_flipped.columns = ["factor", "offset", "equation", "converted result"]
df_flipped.index = symbols
df_flipped.style
| factor | offset | equation | converted result | |
|---|---|---|---|---|
| 10^6 psi | 0.145038 | 0.000000 | 174.0004272460938 * 0.14503773773039605 + 0.0 | 25.236628 |
| ksi | 145.037738 | 0.000000 | 174.0004272460938 * 145.03773773039603 + 0.0 | 25236.628332 |
| psi | 145037.737730 | 0.000000 | 174.0004272460938 * 145037.73773039604 + 0.0 | 25236628.331896 |
| MGO | 125663.706106 | 0.000000 | 174.0004272460938 * 125663.70610560982 + 0.0 | 21865538.551704 |
| Pa | 1000000000.000000 | 0.000000 | 174.0004272460938 * 1000000000.0 + 0.0 | 174000427246.093811 |
| MPa | 1000.000000 | 0.000000 | 174.0004272460938 * 1000.0 + 0.0 | 174000.427246 |
| J/m^3 | 1000000000.000000 | 0.000000 | 174.0004272460938 * 1000000000.0 + 0.0 | 174000427246.093811 |
| MJ/m^3 | 1000.000000 | 0.000000 | 174.0004272460938 * 1000.0 + 0.0 | 174000.427246 |
| erg/cm^3 | 10000000000.000002 | 0.000000 | 174.0004272460938 * 10000000000.000002 + 0.0 | 1740004272460.938477 |
| ft.lbf/in^3 | 12086.478144 | 0.000000 | 174.0004272460938 * 12086.478144199671 + 0.0 | 2103052.360991 |
| kJ/m^3 | 1000000.000000 | 0.000000 | 174.0004272460938 * 1000000.0 + 0.0 | 174000427.246094 |
| inHg | 295299.714445 | 0.000000 | 174.0004272460938 * 295299.7144451761 + 0.0 | 51382276.479110 |
| Ba | 10000000000.000000 | 0.000000 | 174.0004272460938 * 10000000000.0 + 0.0 | 1740004272460.937988 |
| hPa | 10000000.000000 | 0.000000 | 174.0004272460938 * 10000000.0 + 0.0 | 1740004272.460938 |
| mb | 10000000.000000 | 0.000000 | 174.0004272460938 * 10000000.0 + 0.0 | 1740004272.460938 |
| bar | 10000.000000 | 0.000000 | 174.0004272460938 * 10000.0 + 0.0 | 1740004.272461 |
| atm | 9869.232667 | 0.000000 | 174.0004272460938 * 9869.232667160128 + 0.0 | 1717250.700677 |
| torr | 7500637.554192 | 0.000000 | 174.0004272460938 * 7500637.554192106 + 0.0 | 1305114139.047523 |
| lbf/ft^2 | 20885434.233177 | 0.000000 | 174.0004272460938 * 20885434.233177025 + 0.0 | 3634074479.792996 |
| HV | 101.971621 | 0.000000 | 174.0004272460938 * 101.97162129779282 + 0.0 | 17743.105673 |
| kgf/mm^2 | 101.971621 | 0.000000 | 174.0004272460938 * 101.97162129779282 + 0.0 | 17743.105673 |
| dyn/cm^2 | 10000000000.000000 | 0.000000 | 174.0004272460938 * 10000000000.0 + 0.0 | 1740004272460.937988 |
| ft.lbf/ft^3 | 20885434.233177 | 0.000000 | 174.0004272460938 * 20885434.23317702 + 0.0 | 3634074479.792995 |
| in.lbf/in^3 | 145037.737730 | 0.000000 | 174.0004272460938 * 145037.73773039604 + 0.0 | 25236628.331896 |
| J/cm^3 | 1000.000000 | 0.000000 | 174.0004272460938 * 1000.0000000000001 + 0.0 | 174000.427246 |
| kN/cm^2 | 100.000000 | 0.000000 | 174.0004272460938 * 100.0 + 0.0 | 17400.042725 |
| Msi | 0.145038 | 0.000000 | 174.0004272460938 * 0.14503773773039605 + 0.0 | 25.236628 |
| N/mm^2 | 1000.000000 | 0.000000 | 174.0004272460938 * 1000.0 + 0.0 | 174000.427246 |