Creating a script

Initialising

An Extend Python script must do each of the following initialisation steps to work:

  1. Import WorkflowArgumentParser from mapteksdk.workflows.

  2. Create a WorkflowArgumentParser object.

  3. Call the parse_arguments() function on WorkflowArgumentParser.

  4. If you are using WorkflowSelection , then the script must connect to a Maptek application by calling Project().

These initialisation steps are illustrated in the snippet below.

from mapteksdk.workflows import WorkflowArgumentParser
parser = WorkflowArgumentParser() 
parser.parse_arguments()
project = Project()

The script should then follow the procedure outlined below to perform the desired task:

  1. Define input/output connectors

  2. Define component operation

  3. Set output with reference to operation

Defining input/output connectors

You can create your own input connector by using the following code:

parser.declare_input_connector("Input_1", int, connector_name="Input_1", description="Input", default=5)

where

  • Input_1 is the attribute name

  • int is the attribute type

  • Input 1 is the connector name

  • Input is the description

Similarly, you can generate an output connector using the following code:

parser.declare_output_connector("Output_1", int, connector_name="Output 1", description="output")

Defining component operation

Once your input and output connectors are defined, you can define the operation of the component.

number = parser.get_input("Input_1") + 5

In the example above, we are adding five to our input value.

Setting the output

Once your operation is defined, you need to explicitly set the component output.

parser.set_output("Output_1", number)

Summary

It is recommended to structure all Workflow-compatible scripts in the following way:

  1. Import all modules.

  2. Create a WorkflowArgumentParser instance.

  3. Declare all connectors.

  4. Call WorkflowArgumentParser.parse_arguments() .

  5. Use the inputs to perform a useful operation.

  6. Write outputs to the output connectors.