mapteksdk.data.selection_group module
The selection group data type.
- exception SelectionGroupTypeNotSupportedError
Bases:
ValueErrorError raised if the selection group type is not supported.
- add_note()
Exception.add_note(note) – add a note to the exception
- args
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception GroupCannotContainObjectError(group_type, oid)
Bases:
ValueErrorError raised if the selection group cannot contain an object.
- Parameters:
group_type (SelectionGroupType)
oid (ObjectID)
- Return type:
None
- group_type
The group type which triggered this error.
- oid
The Object ID of the object which could not be part of the group.
- add_note()
Exception.add_note(note) – add a note to the exception
- args
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class SelectionGroupType(value)
Bases:
EnumEnum indicating the type of objects stored in a selection group.
- UNDEFINED = 0
The selection group type is undefined.
- DRILLHOLE = 1
The selection group can only contain drillholes.
Warning
This group type only works when the script is connected to GeologyCore. Other applications can’t operate on drillholes and any attempt to add objects to such a group will fail (including attempts to add a drillhole to the group). Note that the blast holes in BlastLogic are not considered drillholes for the purposes of this group type.
- MIXED = 2
The selection group can contain any object.
- FUTURE = 255
The selection group type is not supported by the SDK.
The selection group can be read, but not edited.
- class DrillholeGroupTemplate(owner)
Bases:
objectTemplate used to generate selection group contents.
This class should not be instantiated directly. Instead, use the functions on SelectionGroup to get an instance.
The template consists of a target drillhole database and a set of selection files. If the template is used to set the contents of the selection group, the contents will be set to be all drillholes in the target database which match any inclusion selection files in the template and which do not match any exclusion selection files in the template.
- Parameters:
owner (SelectionGroup)
- property target: ObjectID[DrillholeDatabase]
The drillhole database used to create the drillhole selection.
If the group does not have a target or the target has been deleted or renamed, this will be the null object ID.
- property selection_items: Sequence[ObjectID[SelectionFile]]
The selection files used to generate the group contents.
Any selection files which have been renamed or deleted will be silently ignored and removed from the selection group when changes are saved.
- add_selection_item(oid)
Add a selection file to be used to generate the contents.
- Parameters:
oid (ObjectID[SelectionFile])
- extend_selection_items(oids)
Add multiple selection files to use to generate the contents.
- Parameters:
oids (Iterable[ObjectID[SelectionFile]])
- remove_selection_file(oid)
Remove a selection file from generating the contents.
- Parameters:
oid (ObjectID[SelectionFile])
- refresh()
Refresh the contents of the selection group based on the template.
This will clear the contents of the group and then add each drillhole from the target database for which: * The name matches any inclusion selection file in the template. * The name does not match any exclusion selection file in the template.
- Raises:
RuntimeError – If the target database is not set for this template. If there are no selection items in this template.
- class SelectionGroup(object_id=None, lock_type=LockType.READWRITE, *, rollback_on_error=False)
Bases:
DataObjectA selection which has been saved into the Project.
These can be selected in the explorer to automatically select the objects in the selection group.
- Parameters:
object_id (ObjectID[SelectionGroup] | None)
lock_type (LockType)
rollback_on_error (bool)
- classmethod static_type()
Return this type as stored in a Project.
- Return type:
StaticType
- 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:
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:
- 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:
- 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.
- property id: ObjectID[Self]
Object ID that uniquely references this object in the project.
- Returns:
The unique id of this object.
- Return type:
- 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:
- 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:
- 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
- property contents: Sequence[ObjectID]
The Object IDs of the objects in this selection group.
If this has the DRILLHOLE group_type, this may be a stale selection of drillholes if the drillhole database or selection files have been edited since this selection group has been updated.
- property group_type: SelectionGroupType
The type of this selection group.
- property template: DrillholeGroupTemplate
Template which was used to generate the groups contents.
This is only relevant for drillhole selection groups. Accessing this property for non-drillhole selection groups will result in an error.
The contents of the group may not match the template, as the group can be edited after the template is used to set the contents.
- change_group_type(new_type)
Change the group type to new_type.
This will remove any unsupported objects from the selection group. For example, changing the group type to SelectionGroupType.Drillhole will remove all non-drillhole objects from the group.
- Raises:
SelectionGroupTypeNotSupportedError – If changing the group type to new_type is not supported. This will always be raised for SelectionGroupType.UNDEFINED or SelectionGroupType.FUTURE. If the script is not connected to GeologyCore, this will be raised for SelectionGroupType.DRILLHOLE as well.
- Parameters:
new_type (SelectionGroupType)
- add(oid)
Add oid to this selection group.
- Raises:
ValueError – If oid is an orphan object or the null object.
GroupCannotContainObjectError – If oid cannot be added to groups of this type. The most common case of this is if the group type is SelectionGroupType.DRILLHOLE and oid is not a drillhole or if the script is not connected to GeologyCore.
- Parameters:
oid (ObjectID[DataObject])
- extend(oids)
Add all items in oids to the selection group.
- Raises:
ValueError – If any item in oids is an orphan object or the null object.
GroupCannotContainObjectError – If any object in oids cannot be added to groups of this type. The most common case of this is if the group type is SelectionGroupType.DRILLHOLE and any item in oids is not a drillhole or if the script is not connected to GeologyCore.
- Parameters:
oids (Iterable[ObjectID[DataObject]])
- remove(oid)
Remove oid from the selection group.
This has no effect if oid is not in the group.
- Parameters:
oid (ObjectID[DataObject])
- clear()
Remove all items from this selection group.