mapteksdk.data.selection_file module
The selection file data type.
- class SelectionFile(object_id=None, lock_type=LockType.READWRITE, *, rollback_on_error=False)
Bases:
DataObject
A Vulcan selection file stored within a maptekdb.
A selection file represents a set of names which are either included or excluded from a selection. In the application, these objects can be dragged and dropped onto a drillhole database to create a selection object which contains all of the drillholes with names in the selection file. The Python implementation can be used on any string-based data.
Examples
The most basic way to use a selection file is to add names which should be matched to the file:
>>> with project.new( ... "selection files/basic example", ... SelectionFile ... ) as selection_file: ... selection_file.add("dog") ... print("dog in selection file:", "dog" in selection_file) ... print("Dog in selection file:", "Dog" in selection_file) dog in selection file: True Dog in selection file: False
Note that the matching is case sensitive - “dog” is considered to be in the selection, but “Dog” is not. By calling add() multiple times, or by using extend(), multiple names can be added to the selection:
>>> with project.new( ... "selection files/many example", ... SelectionFile ... ) as selection_file: ... selection_file.extend(("dog", "cat")) ... print("dog in selection file:", "dog" in selection_file) ... print("cat in selection file:", "cat" in selection_file) dog in selection file: True cat in selection file: True
This causes all of these names to be considered as part of the selection. For more complicated matches, two wildcards are available. The first is the ? wildcard. This matches any character. For example:
>>> with project.new( ... "selection files/question mark example", ... SelectionFile ... ) as selection_file: ... selection_file.add("?og") ... print("dog in selection file:", "dog" in selection_file) ... print("cog in selection file:", "cog" in selection_file) ... print("og in selection file:", "og" in selection_file) ... print("frog in selection file:", "frog" in selection_file) dog in selection file: True cog in selection file: True og in selection file: False frog in selection file: False
As the above example shows, adding the name “?og” will cause the selection file to be considered to contain “dog” and “cog”, but not “frog” or “og”. Alternatively, the * wildcard can be used to match zero or more characters. For example:
>>> with project.new( ... "selection files/star example", ... SelectionFile ... ) as selection_file: ... selection_file.add("\*og") ... print("dog in selection file:", "dog" in selection_file) ... print("cog in selection file:", "cog" in selection_file) ... print("og in selection file:", "og" in selection_file) ... print("frog in selection file:", "frog" in selection_file) dog in selection file: True cog in selection file: True og in selection file: True frog in selection file: True
Finally, all matches can be inverted by setting the is_inclusion file to False, as shown in the below example:
>>> with project.new( ... "selection files/invert example", ... SelectionFile ... ) as selection_file: ... selection_file.add("*og") ... selection_file.is_inclusion = False ... print("dog in selection file:", "dog" in selection_file) ... print("cog in selection file:", "cog" in selection_file) ... print("og in selection file:", "og" in selection_file) ... print("frog in selection file:", "frog" in selection_file) ... print("cat in selection file:", "cat" in selection_file) dog in selection file: False cog in selection file: False og in selection file: False frog in selection file: False cat in selection file: True
By changing the selection file from an inclusion file to an exclusion file, the addition of “*og” causes it to contain any name which does not match “*og”, such as “cat” in the above example.
- classmethod static_type()
Return this type as stored in a Project.
- Return type:
StaticType
- add(name)
Add name to this selection file.
This does nothing if the name is already in the selection file.
- Parameters:
name (str) – The name to add to the selection file. This must not be empty. This can include “*” and “?” wildcards. “*” will match any character 0 or more times. “?” will match any character.
- Raises:
ValueError – If name is the empty string.
- Return type:
None
- extend(names)
Add multiple names to the selection file at once.
This is equivalent to calling add for each item in names.
- discard(name)
Remove name from the selection file.
This does nothing if name is not in the selection file.
- Parameters:
name (str)
- Return type:
None
- remove(name)
Remove name from the selection file.
This raises an error if name is not in the selection file.
- Parameters:
name (str)
- clear()
Remove all names from this selection file.
- 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