Viewing allowed discrete values for an attribute using Scripting Toolkit

Andy_Grigg Member, Employee Posts: 15
First Answer First Comment First Anniversary 5 Likes
edited November 2023 in Materials

Today I was asked if it's possible to view the permitted values for a discrete attribute without exporting any data. The answer is yes! Here's a code sample that does this:

from GRANTA_MIScriptingToolkit import granta as mpy

mi = mpy.Session("localhost", autologon=True)
db = mi.get_db(db_key="MI_Restricted_Substances")
table = db.get_table("MaterialUniverse")
attribute = table.attributes["Form"] 

print(f"Allowed values for attribute '{}':")

The line table.attributes["Form"] access the Table.attributes dictionary, which contains AttributeDefinition objects for each attribute defined in the table.

The code attribute.discrete_values then access the AttributeDefinitionDiscrete.discrete_values property, which is a list of the allowed discrete values for that attribute.