Creating a script
Initialising
An Extend Python script must do each of the following initialisation steps to work:
-
Import WorkflowArgumentParser from mapteksdk.workflows.
-
Create a WorkflowArgumentParser object.
-
Call the parse_arguments() function on WorkflowArgumentParser.
-
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:
-
Define input/output connectors
-
Define component operation
-
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:
-
Import all modules.
-
Create a WorkflowArgumentParser instance.
-
Declare all connectors.
-
Use the inputs to perform a useful operation.
-
Write outputs to the output connectors.