Edit Pseudo-attributes¶
View the pseudo-attributes (properties) of a record, and edit a record’s color.
Connect to MI¶
Specify a database and table.
[1]:
from GRANTA_MIScriptingToolkit import granta as mpy
mi = mpy.connect('http://localhost/mi_servicelayer', autologon=True)
db = mi.get_db(db_key='MI_Training')
tab = db.get_table('Training Exercise for Import')
Find a record and view its pseudo-attributes¶
Search for a record (use the first result returned).
[2]:
recs = tab.search_for_records_by_name('Ti')
record = recs[0]
record
[2]:
<Record long name:Ti (Titanium)>
Examine the pseudo-attributes on the record.
[3]:
for name, pa in record.pseudo_attributes.items():
print('{} = {}'.format(name, str(pa.value)))
recordType = Record
recordHistoryIdentity = 121491
recordColor = Red
recordVersionNumber = 0
tableName = Training Exercise for Import
writable = True
parentShortName = Metal
parentName = Metal
parentRecordHistoryIdentity = 121213
shortName = Ti
modifiedDate = 2019-09-12 00:00:00
createdDate = 2018-06-07 00:00:00
releasedDate = 2019-09-12 00:00:00
lastModifier = Granta Design 79
creator = Granta Design 1
subsets = {'Materials'}
name = Ti (Titanium)
Change the record color¶
Pseudo-attribute values can only be changed via the properties on the Record class.
[4]:
record.color = 'White'
record.color
[4]:
'White'
Write your changes to MI (pseudo-attributes do not need to be flagged for update using set_attribute()).
[5]:
mi.update([record])
[5]:
[<Record long name:Ti (Titanium)>]