Attributes won't populate using the Granta SDK/STK 2.0?

Options
James Derrick
James Derrick Administrator, Employee Posts: 248
First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Up Votes
admin
edited June 2023 in Materials

I am creating a new record using the granta stk 2.0, but when I look at it in viewer none of the attributes are populated. Where am I going wrong?

my_record = mi_table.create_record('my record')
my_record.attributes['record ID'] = '000IK'
my_record = session.update([my_record])[0]
Tagged:

Answers

  • James Derrick
    James Derrick Administrator, Employee Posts: 248
    First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Up Votes
    admin
    Answer ✓
    Options

    In the GRANTA MI:Scripting Toolkit v2.0 attributes need to be set on the record, before they are updated. All that is needed to get your code snippet to work is to add the following line:

    my_record.set_attributes([my_record.attributes['record ID']])

    after the record is created but before the Session.update() method is called. Additionally you can set attribute values to be cleared/deleted using the Record.clear_attributes() method. In 2.2 any empty attributes that are added using set_attributes() will be cleared/deleted also.

    Full code:

    my_record = mi_table.create_record('my record')
    my_record.attributes['record ID'] = '000IK'
    my_record.set_attributes([my_record.attributes['record ID']])
    my_record = session.update([my_record])[0]