Create a new record
Connect to MI and specify a database and table.Access a local tabular attribute
Access the (empty) tabular attribute Characterization of this material.__repr__ shows that the tabular attribute is not loaded yet, and so additional information
about the number of rows and columns is not available.
Tabular data is loaded on-demand to improve performance, and reading or modifying the data will load the data
automatically. However, accessing the __repr__ does not trigger the load operation. To load the data manually, use
the .load() method.
Once the attribute is loaded, the __repr__ shows the number of rows and columns.
.column_name, .column_types, and .linked_columns properties list the tabular column names, types, and
whether the column is linked. Each of these properties contain 11 entries, which corresponds to the number of columns
in the tabular attribute, and the size printed in the tabular attribute __repr__.
.value property contains an immutable representation of the current state of the tabular attribute
value. Since the tabular attribute is empty, this returns an empty tuple.
.linking_table and .linking_attribute properties contain the target table and target attribute. This is a
local tabular attribute, so these properties both return None.
Add rows and data
Add a new row to the tabular attribute.TabularRow object is created, which contains a blank cell for each local tabular column, stored in a tuple.
The type of the cell object depends on the type of the column.
Access the tuple of cell objects via the .cells property.
.cells_by_column property returns a mapping of
column name to cell object.
.value property, and picture and file tabular cell classes have a .load() method.
The name of each cell type has a ‘Local’ prefix, which indicates that these are local columns and can be modified.
Each tabular cell class also has a linked counterpart without the ‘Local’ prefix. These are shown in the linked
tabular data example referenced in the introduction. These linked tabular cell classes are read-only and cannot be
modified.
Text cells
Long text cells can accept any string value. Short text cells can accept any string value less than 255 characters. Assign the string to the.value property.
Integer cells
Integer cells can accept any integer value. Assign the integer to the.value property.
Date cells
Date cells accept adatetime.date object. Assign the date to the .value property.
Logical cells
Logical cells accept eitherTrue or False. Assign the boolean to the .value property.
Discrete cells
Discrete cells accept a limited set of allowed strings. To see which values are allowed, use the.possible_discrete_values property.
Point cells
Point cells accept a float value and a unit. In contrast to point attributes, point cells are always single-valued and may not contain parameter information.Range cells
Range cells are similar to point cells, except they accept high and low float values and a unit. Each high and low bound may be marked as inclusive or exclusive, using the.low_value_is_inclusive and
.high_value_is_inclusive property.
Range cell classes differ from range attribute classes in that they do not contain a .value property. Cell values
are set using the .low and .high properties directly.
Picture cells
Picture cells can be populated either by setting.value to a bytes object, or using the .load() method.
File cells
File cells are similar to picture cells, and can also be populated either by setting.value to a bytes object, or
using the .load() method. However, file cells also have a settable .file_name and .description field.
Hyperlink cells
Hyperlink cells accept a.value property which contains the link url, along with .hyperlink_display and
.hyperlink_description properties which control how the hyperlink is displayed in MI Viewer.
AttributeTabular.value property.
This property is useful as a high-level summary of the data, but should not be used for processing. The .rows
property provides a richer representation of the data.
Write changes to Granta MI
Finally, write the changes to the server.Edit tabular data
Most modifications to tabular data can be made as updates to the data already in the database. For example, adding a new row only requires the new row to be uploaded to the database, any existing data is not re-transmitted. The next cell adds two new rows, and adds data to a subset of cells in each.Destructive operations
Destructive operations cannot be completed by modifying data in-place, and can only be completed by overwriting all values.Warning:Destructive editing should be avoided because:
Modifying the order of rows in a tabular attribute is a destructive operation, and by default raises a - This can be slow for attributes with File or Picture attributes, especially if many rows are present.
- Users of Data Updater will face conflicts when applying subsequent updates.
ValueError.
.is_destructive_editing_allowed:
.enable_destructive_editing(). Re-export the tabular attribute with
binary data enabled to avoid an exception when calling mi.update().