mapteksdk.data.block_model_definition module

The block model definition class.

class SubblockRatio(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Enum representing the ratio between subblocks and primary blocks.

These ratios are the ones which are well supported by DomainMCF. A block model can have a different ratio (potentially a different one in each dimension), though such block models are not supported by DomainMCF.

NO_SUBBLOCKS = 1

The model has no subblocks.

ONE_HALF = 0.5

The subblocks are half the size in every dimension.

ONE_QUARTER = 0.25

The subblocks are one quarter the size in every dimension.

ONE_EIGHTH = 0.125

The subblocks are one eighth the size in every dimension.

ONE_SIXTEENTH = 0.0625

The subblocks are one sixteenth the size in every dimension.

class VariableType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

The data types for variables in block model definitions.

STRING = 'string'

The variable stores text.

DOUBLE = 'double'

The variable stores IEEE double precision floating point numbers.

FLOAT = 'float'

The variable stores IEEE single precision floating point numbers.

SHORT = 'integer32'

The variable stores a 32 bit signed integers.

INTEGER = 'integer64'

The variable stores a 64 bit signed integers.

BOOLEAN = 'boolean'

The variable stores boolean values.

BYTE = 'byte'

The variables stores a 8 bit integer.

UNKNOWN = 'unknown'

Python does not recognise the data type.

classmethod from_string(value)

Get a variable type from a string.

Unlike the constructor, this will return UNKNOWN instead of raising an error for values not in the enum.

Parameters:

value (str)

Return type:

Self

property python_type: type[PythonVariableTypes]

The Python type corresponding to this enum value.

property numpy_dtype: dtype

The numpy dtype corresponding to this enum value.

class Variable(backing)

Bases: object

A variable defined in a block model definition.

Parameters:

backing (_Variable)

property name: str

The name of the variable.

property data_type: VariableType

The type of data stored in this variable.

Changing the data type will clear the default value.

property default: PythonVariableTypes

The default value represented as a string.

property description: str

A description of the variable.

class BlockModelDefinition(object_id=None, lock_type=LockType.READWRITE, *, rollback_on_error=False)

Bases: DataObject

The definition for a block model.

This enables configuring the specification for the primary and subblocks of a block model and the variables in the model.

Raises:

InvalidPrimaryBlockSizesError – If on save the primary block sizes are invalid.

Parameters:
  • object_id (ObjectID | None)

  • lock_type (LockType)

  • rollback_on_error (bool)

class VariableType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Type used to represent variables defined by this object.

classmethod from_string(value)

Get a variable type from a string.

Unlike the constructor, this will return UNKNOWN instead of raising an error for values not in the enum.

Parameters:

value (str)

Return type:

Self

property python_type: type[PythonVariableTypes]

The Python type corresponding to this enum value.

property numpy_dtype: dtype

The numpy dtype corresponding to this enum value.

STRING = 'string'

The variable stores text.

DOUBLE = 'double'

The variable stores IEEE double precision floating point numbers.

FLOAT = 'float'

The variable stores IEEE single precision floating point numbers.

SHORT = 'integer32'

The variable stores a 32 bit signed integers.

INTEGER = 'integer64'

The variable stores a 64 bit signed integers.

BOOLEAN = 'boolean'

The variable stores boolean values.

BYTE = 'byte'

The variables stores a 8 bit integer.

UNKNOWN = 'unknown'

Python does not recognise the data type.

class Variable(backing)

Bases: object

Enum used to represent the data type of variables.

Parameters:

backing (_Variable)

property data_type: VariableType

The type of data stored in this variable.

Changing the data type will clear the default value.

property default: PythonVariableTypes

The default value represented as a string.

property description: str

A description of the variable.

property name: str

The name of the variable.

attribute_names()

Returns a list containing the names of all object-level attributes.

Use this to iterate over the object attributes.

Returns:

List containing the attribute names.

Return type:

list

Examples

Iterate over all object attributes of the object stared at “target” and print their values.

>>> from mapteksdk.project import Project
>>> project = Project()
>>> with project.read("target") as read_object:
...     for name in read_object.attribute_names():
...         print(name, ":", read_object.get_attribute(name))
close()

Closes the object.

This should be called as soon as you are finished working with an object. To avoid needing to remember to call this function, open the object using a with block and project.read(), project.new() or project.edit(). Those functions automatically call this function at the end of the with block.

A closed object cannot be used for further reading or writing. The ID of a closed object may be queried and this can then be used to re-open the object.

property closed: bool

If this object has been closed.

Attempting to read or edit a closed object will raise an ObjectClosedError. Such an error typically indicates an error in the script and should not be caught.

Examples

If the object was opened with the Project.new(), Project.edit() or Project.read() in a “with” block, this will be True until the with block is closed and False afterwards.

>>> with project.new("cad/point_set", PointSet) as point_set:
>>>     point_set.points = [[1, 2, 3], [4, 5, 6]]
>>>     print("closed?", point_set.closed)
>>> print("closed?", point_set.closed)
closed? False
closed? True
property created_date: datetime

The date and time (in UTC) of when this object was created.

Returns:

The date and time the object was created. 0:0:0 1/1/1970 if the operation failed.

Return type:

datetime.datetime

delete_all_attributes()

Delete all object attributes attached to an object.

This only deletes object attributes and has no effect on PrimitiveAttributes.

Raises:

RuntimeError – If all attributes cannot be deleted.

delete_attribute(attribute)

Deletes a single object-level attribute.

Deleting a non-existent object attribute will not raise an error.

Parameters:

attribute (str) – Name of attribute to delete.

Returns:

True if the object attribute existed and was deleted; False if the object attribute did not exist.

Return type:

bool

Raises:

RuntimeError – If the attribute cannot be deleted.

get_attribute(name)

Returns the value for the attribute with the specified name.

Parameters:

name (str) – The name of the object attribute to get the value for.

Returns:

The value of the object attribute name. For dtype = datetime.datetime this is an integer representing the number of milliseconds since 1st Jan 1970. For dtype = datetime.date this is a tuple of the form: (year, month, day).

Return type:

ObjectAttributeTypes

Raises:

KeyError – If there is no object attribute called name.

Warning

In the future this function may be changed to return datetime.datetime and datetime.date objects instead of the current representation for object attributes of type datetime.datetime or datetime.date.

get_attribute_type(name)

Returns the type of the attribute with the specified name.

Parameters:

name (str) – Name of the attribute whose type should be returned.

Returns:

The type of the object attribute name.

Return type:

ObjectAttributeDataTypes

Raises:

KeyError – If there is no object attribute called name.

property id: ObjectID[Self]

Object ID that uniquely references this object in the project.

Returns:

The unique id of this object.

Return type:

ObjectID

property is_read_only: bool

If this object is read-only.

This will return True if the object was open with Project.read() and False if it was open with Project.edit() or Project.new(). Attempting to edit a read-only object will raise an error.

property lock_type: LockType

Indicates whether operating in read-only or read-write mode.

Use the is_read_only property instead for checking if an object is open for reading or editing.

Returns:

The type of lock on this object. This will be LockType.ReadWrite if the object is open for editing and LockType.Read if the object is open for reading.

Return type:

LockType

property modified_date: datetime

The date and time (in UTC) of when this object was last modified.

Returns:

The date and time this object was last modified. 0:0:0 1/1/1970 if the operation failed.

Return type:

datetime.datetime

save()

Save the changes made to the object.

Generally a user does not need to call this function, because it is called automatically at the end of a with block using Project.new() or Project.edit().

Returns:

The change reasons for the operation. This depends on what changes to the object were saved. If the api_version is less than 1.9, this always returns ChangeReasons.NO_CHANGE.

Return type:

ChangeReasons

set_attribute(name, dtype, data)

Sets the value for the object attribute with the specified name.

This will overwrite any existing attribute with the specified name.

Parameters:
  • name (str) – The name of the object attribute for which the value should be set.

  • dtype (ObjectAttributeDataTypes | type[datetime.datetime | datetime.date | bool | int | float | str]) – The type of data to assign to the attribute. This should be a type from the ctypes module or datetime.datetime or datetime.date. Passing bool is equivalent to passing ctypes.c_bool. Passing str is equivalent to passing ctypes.c_char_p. Passing int is equivalent to passing ctypes.c_int16. Passing float is equivalent to passing ctypes.c_double.

  • data (Any) – The value to assign to object attribute name. For dtype = datetime.datetime this can either be a datetime object or timestamp which will be passed directly to datetime.fromtimestamp(). For dtype = datetime.date this can either be a date object or a tuple of the form: (year, month, day).

Raises:
  • ValueError – If dtype is an unsupported type.

  • TypeError – If value is an inappropriate type for object attribute name.

  • ValueError – If name starts or ends with whitespace or is empty.

  • RuntimeError – If a different error occurs.

Notes

If an error occurs after adding a new object attribute or editing an existing object attribute resulting in save() not being called, the changes to the object attributes can only be undone if the application’s API version is 1.6 or greater.

Prior to mapteksdk 1.6: Adding new object attributes, or editing the values of object attributes, will not be undone if an error occurs.

Examples

Create an object attribute on an object at “target” and then read its value.

>>> import ctypes
>>> from mapteksdk.project import Project
>>> project = Project()
>>> with project.edit("target") as edit_object:
...     edit_object.set_attribute("count", ctypes.c_int16, 0)
... with project.read("target") as read_object:
...     print(read_object.get_attribute("count"))
0
classmethod static_type()

Return this type as stored in a Project.

property block_size: tuple[float, float, float]

The size of the primary blocks.

This is of the form (x_size, y_size, z_size).

property subblock_size: tuple[float, float, float]

The size of the subblocks.

This is of the form (x_size, y_size, z_size). This will be equal to the block_size if the model is dense.

property rounded_subblock_size: tuple[float, float, float]

The size of the subblocks rounded to the supported ratio.

property subblock_ratio: tuple[float, float, float]

The subblock ratio in each dimension.

This is of the form: (x_ratio, y_ratio, z_ratio) where each ratio is between 0 and 1.

Notes

This is the block size divided by the sub block size. For block models supported by DomainMCF, all three elements of the returned tuple will be the same and will correspond to a value in the SubblockRatio enum.

property supported_subblock_ratio: SubblockRatio

The rounded ratio of the primary blocks to the subblocks.

This is the subblock ratio rounded to the closest ratio in the SubblockRatio enum. This is the ratio displayed in the “Edit Block Model Definition” panel in GeologyCore.

property block_counts: tuple[int, int, int]

The block counts in the form (x_count, y_count, z_count).

Raises:

RuntimeError – If this is set before the block sizes.

property origin: tuple[float, float, float]

The origin of the block model this defines.

property orientation: tuple[float, float, float]

The rotation of the block model in the form (dip, plunge, bearing).

This differs from other orientation (and rotation) properties in the SDK because the dip, plunge and bearing of a block model definition can be between -360 and 360 degrees (inclusive).

Though this is true to the values which can be stored in a block model definition file (.bdf), there are orientation values which are non-equal which result in the same rotation (i.e. definition_a.orientation != definition_b.orientation does not guarantee that their rotations are not the same).

property model_extent: tuple[float, float, float]

The maximum x, y and z values in the model.

This matches the extent displayed in the “Edit Block Model Definition” transaction. This is the block size multiplied by the block count. See the extent property for the actual extent of the definition.

set_block_size(block_size, subblock_ratio=SubblockRatio.NO_SUBBLOCKS)

Set the size of the blocks and subblocks.

This only enables setting the subblock sizes to values which are expected to work with DomainMCF. The ratio of the block sizes is restricted based on the values in the SubblockRatio enum.

Parameters:
  • block_size (tuple[float, float, float]) – The size for the primary blocks in the form (x_size, y_size, z_size).

  • subblock_ratio (SubblockRatio) – The ratio of the subblock size to the primary block size. This is SubblockRatio.NO_SUBBLOCKS by default, resulting in a dense block model.

variables()

Get a sequence containing the variables of the block model.

This returns a new sequence containing new copies of the Variable objects each time this is called. Old return values become stale when variables are added or deleted.

Return type:

Sequence[Variable]

add_variable(name: str, data_type: Literal[VariableType.BOOLEAN], default: bool | None = None, description: str = '')
add_variable(name: str, data_type: Literal[VariableType.STRING], default: str | None = None, description: str = '')
add_variable(name: str, data_type: Literal[VariableType.FLOAT, VariableType.DOUBLE], default: float | None = None, description: str = '')
add_variable(name: str, data_type: Literal[VariableType.INTEGER, VariableType.SHORT, VariableType.BYTE], default: int | None = None, description: str = '')
add_variable(name: str, data_type: VariableType, default: str | float | bool | None = None, description: str = '')

Add a new variable to the block model definition.

Parameters:
  • name – The name of the variable.

  • data_type – The type of data stored in this variable.

  • default – The default value of the variable represented as a string. It is the caller’s responsibility to ensure this is a valid default value for the data type.

  • description – Short textual description of the variable.

Raises:
  • ValueError

    • If data_type is VariableType.UNKNOWN. * If there is already a variable with name. * If default is not a valid value for data_type

  • TypeError – If default is a type which cannot be converted to data_type.

remove_variable(variable)

Remove variable from the definition.

This does nothing if variable is not in the definition.

Parameters:

variable (Variable)