mapteksdk.workflows.workflow_selection module

ConnectorType subclasses dependent on the data module.

class WorkflowSelection(selection_string)

Bases: ConnectorType

Class representing a read-only list of ObjectIDs. Pass this to declare_input_connector for input connectors expecting a selection - the lists of objects given by the ‘Maptek Database Object’ connectors of many components.

Iterating over this object will iterate over the ObjectIDs in the selection.

You should not access the contents of this object until after Project() has been called.

Parameters

selection_string (str) – String representing the selection.

Raises
  • OSError – If the contents are accessed before Project() has been called.

  • ValueError – If part of the selection cannot be converted to an ObjectID.

Warning

Ensure the ObjectIDs passed to this class are from the same project as is opened with Project() otherwise the ObjectIDs may refer to a completely different object.

Notes

This class does not support object paths which contain quotation marks or commas.

Examples

Script which takes a selection of objects and returns their centroid via a list output connector. This script would have one input connector “Selection” which accepts a selection. There is also one output connector “Centroid” which will be set to the centroid of all of the points in the objects in the selection. Note that this script does not honour point selection.

>>> from mapteksdk.project import Project
>>> from mapteksdk.workflows import (WorkflowArgumentParser,
...                                  WorkflowSelection,
...                                  Point3DConnectorType)
>>> import numpy as np
>>> parser = WorkflowArgumentParser(
...     description="Get the centroid of objects with points")
>>> parser.declare_input_connector(
...     "selection",
...     WorkflowSelection,
...     description="Objects to find the centroid of.")
>>> parser.declare_output_connector(
...     "Centroid",
...     Point3DConnectorType,
...     description="The centroid of the points in the objects.")
>>> parser.parse_arguments() # Must call before Project().
>>> project = Project() # Must call before get_ids().
>>> sums = np.zeros(3)
>>> count = 0
>>> for oid in parser["selection"]:
...     with project.read(oid) as read_object:
...         if not hasattr(read_object, "points"): continue
...         sums += np.sum(read_object.points, axis=0)
...         count += read_object.point_count
>>> result = sums / count
>>> parser.set_output("Centroid", result)
>>> parser.flush_output()
classmethod type_string()

The string representation of the type to report to the Workflow as the type for the Connector.

Returns

String representation of the type to report to the workflow.

Return type

str

classmethod from_string(string_value)

Convert a string value from an input connector to the corresponding python type and returns it.

Returns

The python representation of the string value.

Return type

any

Raises
  • TypeError – If string_value is not a supported type.

  • ValueError – If string_value is the correct type but an invalid value.

Parameters

string_value (str) –

classmethod to_json(value)

Converts the value to a json-serializable value.

This is used to convert python values to json values to be passed to the workflow for output connectors.

Returns

Json serializable representation of value.

Return type

json-serializable

Raises
  • TypeError – If value is not a supported type.

  • ValueError – If value is the correct type but an invalid value.

Parameters

value (str | Iterable) –

property ids: list[ObjectID[DataObject]]

Return the IDs in the selection as a list. This must be called after Project() has been called. Object IDs only have meaning within a Project.

Returns

ObjectIDs in the selection.

Return type

list of ObjectID

Raises
  • ValueError – If any string cannot be converted to an ObjectID.

  • OSError – If called before Project() is called.

classmethod to_default_json(value)

Converts the value to a json serializable default.

This allows for specifying a different representation for default values. The output of this function should not include lists.

Overwrite this function to raise an error to indicate that default values are not supported.

By default this calls to_json.

Returns

String representation of value.

Return type

str

Raises
  • TypeError – If value is not a supported type.

  • ValueError – If value is the correct type but an invalid value.

Parameters

value (Any) –