mapteksdk.view module

Interaction with a view in an applicable Maptek application.

The first step is opening a new view which returns a view controller for the new view. From there you can control the view by adding/removing objects, hiding/showing objects and querying what objects are in the view.

>>> from mapteksdk.project import Project
>>> import mapteksdk.operations as operations
>>> project = Project()
>>> view = operations.open_new_view()
>>> view.add_objects([project.find_object('/cad')])
exception ViewNoLongerExists

Bases: RuntimeError

Exception for when a view is expected but it no longer exists.

The most common occurrence for this exception is when the view has been closed.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class ObjectFilter

Bases: object

Describes different ways to filter what objects are returned by a ViewController.

DEFAULT = 0

Default - return all object except transient and background objects but ignoring visibility, and selection

Transient objects are objects that are in the view for previewing an operation or providing additional clarity while a tool in the application is running.

VISIBLE_ONLY = 1

Only return objects that are visible in the view.

HIDDEN_ONLY = 2

Only return objects that are hidden in the view.

SELECTED_ONLY = 4

Only return objects that are selected and are in the view.

class ViewController(view_id)

Bases: object

Provides access onto a specified view.

This allows for objects to be added/removed/shown and hidden.

Parameters

view_id (ObjectID[DataObject]) –

property window_title: str

Return the window title.

This is the name of the view window as seen in the application.

close()

Close the view.

Avoid closing views that you didn’t open, as such avoid closing the view if it came from a non-empty active view. This is because you may close a view that was being used by another tool in the application.

A case where closing the view is a good idea is if the script creates one and is interactive and long-running. Think about when the script is done if the person running the script would miss seeing what is in the view, would find it a hassle to have to close it themself or if the content is no longer relevant after the script has exited.

Examples

Opens a new view then closes it.

>>> import mapteksdk.operations as operations
>>> project = Project()
>>> view = operations.open_new_view()
>>> input('Press enter to finish')
>>> view.close()
objects_in_view(object_filter=0)

Return a list of objects that are in the the view.

Parameters

object_filter (ObjectFilter) – A filter that limits what objects are returned.

Returns

A list of object IDs of objects that are in the view that meet the filter criteria.

Return type

list

add_objects(objects)

Adds the provided objects to the view.

Parameters

objects (Iterable[Union[ObjectID, DataObject, str]]) – A list of IDs of objects to add to the view.

add_object(object_to_add)

Add a single object to the view.

Parameters

object_to_add (Union[ObjectID, DataObject, str]) – The object to add, the ObjectID of the object to add, or a path string for the object to add.

remove_objects(objects)

Removes the provided objects from the view if present.

Removing objects not in the view will do nothing.

Parameters

objects (Iterable[Union[ObjectID, DataObject, str]]) – A list of IDs of objects to remove from the view.

remove_object(object_to_remove)

Remove a single object from the view.

Parameters

object_to_remove (Union[ObjectID, DataObject, str]) – The object to remove, the ObjectID of the object to remove, or a path string for the object to remove.

hide_objects(objects)

Hide the provided objects in the view.

Hiding objects not in the view will do nothing.

Parameters

objects (Iterable[Union[ObjectID, DataObject, str]]) – A list of IDs of objects to hide.

hide_object(object_to_hide)

Hide a single object in the view.

Parameters

object_to_hide (Union[ObjectID, DataObject, str]) – The object to hide, the ObjectID of the object to hide, or a path string for the object to hide.

show_objects(objects)

Show the provided objects in the view (if hidden).

If the objects are not in the view then they won’t be shown.

Parameters

objects (Iterable[Union[ObjectID, DataObject, str]]) – A list of IDs of objects to hide.

show_object(object_to_show)

Show a single hidden object in the view.

Parameters

object_to_show (Union[ObjectID, DataObject, str]) – The object to show, the ObjectID of the object to show, or a path string for the object to show.

property background_colour: Tuple[int, int, int, int]

The background colour of the view window.

This is represented as a tuple containing red, green, blue, alpha values of the colour. Each value is an integer in the range [0, 255].

When changing the background colour, the alpha is optional and the colour may be given as either a tuple, list or ndarray.