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.

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 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 SectionMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

Enumeration of the available section modes.

NO_MODE = 0

No section mode is active.

POSITIVE_HALF_SPACE = 1

Only show data on the normal side of the plane.

The clip plane is defined to be the action plane in the direction of the plane normal.

A section width may be defined to only show the data on the normal side of the plane that is at a maximum the section width away.

NEGATIVE_HALF_SPACE = 2

Only show data on the negative side of the plane.

The clip plane is defined to be the action plane in the opposite direction of the plane normal.

A section width may be defined to only show the data on the normal side of the plane that is at a maximum the section width away.

STRIP = 3

Show data between two parallel planes.

The clip planes are defined to be half the section width either side of the plane.

from_bytes(bytes, byteorder='big', *, signed=False)

Return the integer represented by the given array of bytes.

bytes

Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use ‘sys.byteorder’ as the byte order value. Default is to use ‘big’.

signed

Indicates whether two’s complement is used to represent the integer.

to_bytes(length=1, byteorder='big', *, signed=False)

Return an array of bytes representing an integer.

Parameters:
  • length – Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. Default is length 1.

  • byteorder – The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use ‘sys.byteorder’ as the byte order value. Default is to use ‘big’.

  • signed – Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.

as_integer_ratio()

Return integer ratio.

Return a pair of integers, whose ratio is exactly equal to the original int and with a positive denominator.

>>> (10).as_integer_ratio()
(10, 1)
>>> (-10).as_integer_ratio()
(-10, 1)
>>> (0).as_integer_ratio()
(0, 1)
bit_count()

Number of ones in the binary representation of the absolute value of self.

Also known as the population count.

>>> bin(13)
'0b1101'
>>> (13).bit_count()
3
bit_length()

Number of bits necessary to represent self in binary.

>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
conjugate()

Returns self, the complex conjugate of any int.

denominator

the denominator of a rational number in lowest terms

imag

the imaginary part of a complex number

numerator

the numerator of a rational number in lowest terms

real

the real part of a complex number

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

Bases: IntEnum

Enumeration of the section stepping directions.

This refers to the screen-space directions in which to move the section.

The two compound directions (LEFT_AND_UP and RIGHT_AND_DOWN) will move the section in the direction of the strongest component of the section plane normal as seen in screen-space (horizontal or vertical).

LEFT = 0
RIGHT = 1
UP = 2
DOWN = 3
LEFT_AND_UP = 4
RIGHT_AND_DOWN = 5
from_bytes(bytes, byteorder='big', *, signed=False)

Return the integer represented by the given array of bytes.

bytes

Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use ‘sys.byteorder’ as the byte order value. Default is to use ‘big’.

signed

Indicates whether two’s complement is used to represent the integer.

to_bytes(length=1, byteorder='big', *, signed=False)

Return an array of bytes representing an integer.

Parameters:
  • length (SupportsIndex) – Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. Default is length 1.

  • byteorder (Literal['little', 'big']) – The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use ‘sys.byteorder’ as the byte order value. Default is to use ‘big’.

  • signed (bool) – Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.

Return type:

bytes

as_integer_ratio()

Return integer ratio.

Return a pair of integers, whose ratio is exactly equal to the original int and with a positive denominator.

>>> (10).as_integer_ratio()
(10, 1)
>>> (-10).as_integer_ratio()
(-10, 1)
>>> (0).as_integer_ratio()
(0, 1)
bit_count()

Number of ones in the binary representation of the absolute value of self.

Also known as the population count.

>>> bin(13)
'0b1101'
>>> (13).bit_count()
3
bit_length()

Number of bits necessary to represent self in binary.

>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
conjugate()

Returns self, the complex conjugate of any int.

denominator

the denominator of a rational number in lowest terms

imag

the imaginary part of a complex number

numerator

the numerator of a rational number in lowest terms

real

the real part of a complex number

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

Bases: FixedInteger32Mixin, IntEnum

Enumeration describing the possible restrictions on transient geometry.

The options are:

  • No restrictions (show in all picked views).

  • Only shown in the specific view (after pick in that view).

  • Only shown in views that are not the specified view (after pick in that view).

NO_RESTRICTIONS = 0
ONLY_IN_VIEW = 1
NEVER_IN_VIEW = 2
from_bytes(bytes, byteorder='big', *, signed=False)

Return the integer represented by the given array of bytes.

bytes

Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use ‘sys.byteorder’ as the byte order value. Default is to use ‘big’.

signed

Indicates whether two’s complement is used to represent the integer.

to_bytes(length=1, byteorder='big', *, signed=False)

Return an array of bytes representing an integer.

Parameters:
  • length (SupportsIndex) – Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. Default is length 1.

  • byteorder (Literal['little', 'big']) – The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use ‘sys.byteorder’ as the byte order value. Default is to use ‘big’.

  • signed (bool) – Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.

Return type:

bytes

as_integer_ratio()

Return integer ratio.

Return a pair of integers, whose ratio is exactly equal to the original int and with a positive denominator.

>>> (10).as_integer_ratio()
(10, 1)
>>> (-10).as_integer_ratio()
(-10, 1)
>>> (0).as_integer_ratio()
(0, 1)
bit_count()

Number of ones in the binary representation of the absolute value of self.

Also known as the population count.

>>> bin(13)
'0b1101'
>>> (13).bit_count()
3
bit_length()

Number of bits necessary to represent self in binary.

>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
conjugate()

Returns self, the complex conjugate of any int.

denominator

the denominator of a rational number in lowest terms

imag

the imaginary part of a complex number

numerator

the numerator of a rational number in lowest terms

real

the real part of a complex number

storage_type: ClassVar = <class 'ctypes.c_long'>
class TransientGeometrySettings

Bases: InlineMessage

Settings for transient geometry.

These affect how an object is treated when they are transient geometry.

is_clippable: bool = True
is_pickable: bool = False
is_selectable: bool = False
is_initially_visible: bool = True
restrict_mode: TransientGeometryRestrictMode = 0
restricted_views: List[ObjectID] = []
classmethod from_handle(handle)

Read the message from a handle.

Returns:

A message object populated with the values from the given handle.

Return type:

cls

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()
scene_extents()

Return the scene extents of this view.

Return type:

Extent

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[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 (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[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 (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[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 (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[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 (ObjectID | DataObject | str) – The object to show, the ObjectID of the object to show, or a path string for the object to show.

add_transient_object(object_to_add, settings=TransientGeometrySettings(is_clippable=True, is_pickable=False, is_selectable=False))

Add a single object to the view as a transient object.

Transient objects by default are not pickable or selectable. They are typically used to show a preview of some operation.

You are responsible for removing the object from the view when you are done with it (or if you opened the view then close the view). The object should not be left in the view after you are done with it as this will leave the user with only the option of closing the view to get rid of it themselves. If you promote the transient object then it doesn’t need to be removed.

Parameters:
  • object_to_add (ObjectID | DataObject | str) – The object to add, the ObjectID of the object to add, or a path string for the object to add.

  • settings (TransientGeometrySettings) – The transient geometry settings that apply to the object_to_add.

See also

remove_object

To remove the object from the view.

promote_transient_object

To promote the transient object.

add_transient_objects(objects, settings=TransientGeometrySettings(is_clippable=True, is_pickable=False, is_selectable=False))

Adds the provided objects to the view as transient objects.

Transient objects by default are not pickable or selectable. They are typically used to show a preview of some operation.

You are responsible for removing the object from the view when you are done with it (or if you opened the view then close the view). The object should not be left in the view after you are done with it as this will leave the user with only the option of closing the view to get rid of it themselves. If you promote the transient object then it doesn’t need to be removed.

Parameters:

See also

remove_objects

To remove the object from the view.

promote_transient_objects

To promote transient objects.

promote_transient_object(object)

Promote a transient object to being a permanent object.

This is relevant to the view only, to ensure the geometry persists it should be added to the project.

Parameters:

object (ObjectID | DataObject | str) –

promote_transient_objects(objects)

Promote transient objects to being permanent objects.

This is relevant to the view only, to ensure the objects persists they should be added to the project.

Parameters:

objects (Iterable[ObjectID | DataObject | str]) –

transient_objects_in_view()

Return the transient objects that are in the the view and their settings.

Returns:

A list of each transient object and their corresponding settings.

Return type:

list

action_plane_section_widths()

Return the widths of the section in this view.

Return type:

Tuple[float, float]

set_action_plane_section_widths(back_width, front_width)

Change the section width of the view.

This will only take affect if view’s section mode is not SectionMode.NO_MODE.

It is typical for the same width to be given for both the front and back.

Parameters:
  • back_width (float) – The width of the section from the action plane to the back.

  • front_width (float) – The width of the section from the action plane to the front.

See also

action_plane_section_mode

Query the current section mode

set_action_plane_section_mode

Set the current section modes (enable sectioning)

action_plane_section_mode()

Return the current selection mode of this view.

Return type:

SectionMode

set_action_plane_section_mode(section_mode)

Change the view’s section mode to the mode given.

Parameters:

section_mode (SectionMode) – The section mode to change to.

Examples

Turn on sectioning in the current view.

>>> from mapteksdk.project import Project
>>> from mapteksdk.operations import active_view
>>> from mapteksdk.view import SectionMode
>>> project = Project()
>>> view = active_view()
>>> view.set_action_plane_section_mode(SectionMode.STRIP)

Turn off sectioning in the current view.

>>> from mapteksdk.project import Project
>>> from mapteksdk.operations import active_view
>>> from mapteksdk.view import SectionMode
>>> project = Project()
>>> view = active_view()
>>> view.set_action_plane_section_mode(SectionMode.NO_MODE)
set_action_plane(plane)

Set the action plane in this view.

Parameters:

plane (Plane) – The plane to use for the action plane.

action_plane_section_step_distance()

The distance that the action plane will move if it is stepped by.

Return type:

float

set_action_plane_section_step_distance(step_distance)

Change the section step distance of the view.

Parameters:

step_distance (float) – The distance to step forward/back with the section.

See also

step_action_plane_section_forwards

Step forwards by the last distance.

step_action_plane_section_backwards

Step backwards by the last distance.

step_action_plane_section_forwards()

Step (moves) the action plane forwards.

The distance the plane will move is based on the last set step distance for the view.

See also

set_action_plane_section_step_distance

Set the step distance.

step_action_plane_section_backwards

Step in the other direction.

step_action_plane_section_backwards()

Step (moves) the action plane backwards.

The distance the plane will move is based on the last set step distance for the view.

See also

set_action_plane_section_step_distance

Set the step distance.

step_action_plane_section_forwards

Step in the other direction.

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.