mapteksdk.workflows.workflow_selection module
ConnectorType subclasses dependent on the data module.
- class WorkflowSelection(selection_string)
Bases:
mapteksdk.workflows.connector_type.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()
- classmethod from_string(string_value)
- classmethod to_json(value)
- property ids
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.