MMpy.FileStruct.add_field

Syntax

structure.add_field(field_name, field_type, field_width=1, field_precision=0)

Description

Add a new field to a file structure object.

Parameters

Name
Type
Description

field_name 

str Name of the field.
field_type MMpy.FieldType Type of the field.
field_width int (optional) Width of the field. This changes meaning depending on the field type selected. See notes below.
field_precision int (optional) Precision of the field. This changes meaning depending on the field type selected. See notes below.

Returns

Type
Description
bool Returns True if the field was added, False otherwise.

See Also

MMpy.FileStruct.fields

MMpy.File.get_field_id()

Notes

This will add the new field to the structure. Before using it, you must still query the field ID after it has been added, for example through MMpy.File.get_field_id().

The meaning of field_width and field_precision depends on the given field type. See Modify File Structure for more information.

Valid choices for field_type are:

  • MMpy.FieldType.character
  • MMpy.FieldType.numeric
  • MMpy.FieldType.real
  • MMpy.FieldType.float
  • MMpy.FieldType.long
  • MMpy.FieldType.short
  • MMpy.FieldType.unknown

Examples

file_path = MMpy.Project.path() + 'test.DAT'

file = MMpy.File()
file.open(path)

structure = file.structure
structure.add_field('NewRealField', MMpy.FieldType.real, field_precision=4)
structure.add_field('NewCharField', MMpy.FieldType.character, field_width=100)

file.structure = structure

file.close()

Resource ID

IDPH_FILESTRUCT_ADDFLD