Unknown Inputs
When constructing a WorkflowArgumentParser object, setting the allow_unknown_attributes flag to True causes the script to read every possible input from the workflow component.
Essentially:
-
If allow_unknown_attributes=False (the default):
-
This causes the workflow component to only pass inputs that correspond to a declared input connector to the script.
-
If an input that doesn’t correspond to a declared input connector reaches the script, the script will fail with an error.
-
-
If allow_unknown_attributes=True:
-
The workflow component will pass every input attribute to the script.
-
Inputs that do not correspond to input connectors are available via the unknown_attribute function.
-
The unknown_attribute_names property returns an iterable containing the names of every attribute that does not correspond to an input connector. The values of these attributes can then be read via the unknown_attribute function.
The following script demonstrates using this to take all of the input attributes and concatenate their values into a single list:
from mapteksdk.workflows import WorkflowArgumentParser
if __name__ == "__main__":
parser = WorkflowArgumentParser(allow_unknown_attributes=True)
parser.declare_output_connector(
"output",
list,
"Output",
"The input property values concatenated into a list.")
parser.parse_arguments()
output_list = []
for name in parser.unknown_attribute_names:
value = parser.unknown_attribute(name, str)
if value != "":
output_list.append(value)
parser.set_output("output", output_list)
The following animation demonstrates a simple workflow that uses the above script.
The input attributes are:
| Name | Value |
|---|---|
| hello | Hello |
| world | World! |