Main Content

addTask

Add task instance to process model

    Description

    taskObj = addTask(pm,taskNameOrInstance) adds the task specified by taskNameOrInstance to the process model. You can access the task using the task object taskObj. For more information, see Add Tasks to Process.

    This functionality requires CI/CD Automation for Simulink Check.

    example

    taskObj = addTask(___,Name=Value) specifies the properties of the task using one or more Name=Value arguments.

    Examples

    collapse all

    You can use the addTask function to create function-based tasks directly in the process model.

    Open the Process Advisor example project.

    processAdvisorExampleStart

    The model AHRS_Voter opens with the Process Advisor pane to the left of the Simulink® canvas.

    In the Process Advisor pane, click the Edit process model button to open the processmodel.m file for the project.

    Replace the contents of the processmodel.m file with this code:

    function processmodel(pm)
        arguments
            pm padv.ProcessModel
        end
    
        addTask(pm,"MyCustomTask",Action=@SayHello,...
            IterationQuery=padv.builtin.query.FindModels);
    
    end
    
    function results = SayHello(~)
        disp("Hello, World!");
        results = padv.TaskResult;
        results.Values.Pass = 1;
    end

    This code adds a task, MyCustomTask to the process model while specifying that the task runs the function SayHello one time for each model found in the project. The function SayHello also specifies the results returned by the task.

    Input Arguments

    collapse all

    Process for project, specified as a padv.ProcessModel object.

    Example: pm = padv.ProcessModel

    Name or instance of a task, specified as a string or padv.Task object.

    Example: "NameOfMyTask"

    Example: padv.builtin.task.RunModelStandards

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: addTask(pm,"RunOnceForEachModel",IterationQuery=padv.builtin.query.FindModels)

    Human readable name that appears in the Tasks column of the Process Advisor app, specified as a string. By default, the Process Advisor app uses the Name property of the task as the Title.

    Example: "My Task"

    Data Types: string

    Artifacts that task iterates over, specified as a padv.Query object or the name of a padv.Query object. By default, task objects run one time and are associated with the project. When you specify IterationQuery, the task runs one time for each artifact specified by the padv.Query. In the Process Advisor app, the artifacts specified by IterationQuery appear under task title.

    For example, if the IterationQuery for a task finds three models, Model_A, Model_B, and Model_C, the build system creates three task iterations under the title of the task in the Tasks column.

    How the task with the models specified by the IterationQuery appears in the Process Advisor app

    Each of the artifacts under the task title represents a task iteration.

    For examples of different IterationQuery values:

    • If you have a task where the IterationQuery uses padv.builtin.query.FindModels to find each of the models in the project, the build system creates a task iteration for each model.

    • If you have a task where the IterationQuery uses padv.builtin.query.FindProjectFile to find the project file, the build system creates a task iteration for the project file.

    • If you have a task where the IterationQuery uses padv.builtin.query.FindTopModels to find top models in the project, the build system creates a task iteration for each top model.

    The Process Advisor app showing the task iterations for each example

    Example: IterationQuery = padv.builtin.query.FindModels

    Data Types: string

    Inputs to the task, specified as:

    • a padv.Query object

    • the name of padv.Query object

    • an array of padv.Query objects

    • an array of names of padv.Query objects

    By default, padv.Task does not have inputs. When you specify InputQueries, the task uses the artifacts specified by the specified query or queries as an input.

    Suppose a task runs once for each model in the project and you want to provide the models as inputs to the task. If you specify InputQueries as the built-in query padv.builtin.query.GetIterationArtifact, the query returns each artifact that the tasks iterates over, which in this example is each of the models in the project.

    Example: InputQueries = padv.builtin.query.GetIterationArtifact

    Artifact dependencies for task inputs, specified as a padv.Query object or the name of a padv.Query object.

    The build system runs the query specified by InputDependencyQuery to find the dependencies for the task inputs, since those dependencies can impact if task results are up-to-date. Typically, you specify InputDependencyQuery as padv.builtin.query.GetDependentArtifacts to get the dependent artifacts for each task input. For example, if you specify a model as an input to a task and you specify InputDependencyQuery as padv.builtin.query.GetDependentArtifacts, the build system can find artifacts, such as data dictionaries, that the model uses.

    Example: InputDependencyQuery = padv.builtin.query.GetDependentArtifacts

    Function that the task runs, specified as the function handle. When you run the task, the task runs the function specified by the function handle.

    For example, if you want the task to run the function myFunction, specify Action as @myFunction.

    Example: Action = @myFunction

    Data Types: function_handle

    Type of artifact, specified as one or more of the values listed in this table. To specify multiple values, use an array. The build system uses the artifact type to identify and categorize the different file types and modeling constructs in your project.

    CategoryArtifact TypeDescription

    MATLAB®

    "m_class"MATLAB class
    "m_file"MATLAB file
    "m_func"MATLAB function
    "m_method"MATLAB class method
    "m_property"MATLAB class property

    Model Advisor

    "ma_config_file"Model Advisor configuration file
    "ma_justification_file"Model Advisor justification file

    Process Advisor

    "padv_dep_artifacts"

    Related artifacts that current artifact depends on

    "padv_output_file"

    Process Advisor output file

    Project

    "project"Current project file

    Requirements

    "mwreq_file"Requirement file (since R2024b)
    "mwreq_item"Requirement (since R2024b)

    "sl_req"

    Requirement (for R2024a and earlier)
    "sl_req_file"Requirement file (for R2024a and earlier)
    "sl_req_table"Requirements Table

    Stateflow®

    "sf_chart"Stateflow chart
    "sf_graphical_fcn"Stateflow graphical function
    "sf_group"Stateflow group
    "sf_state"Stateflow state
    "sf_state_transition_chart"Stateflow state transition chart
    "sf_truth_table"Stateflow truth table

    Simulink

    "sl_block_diagram"Block diagram
    "sl_data_dictionary_file"Data dictionary file
    "sl_embedded_matlab_fcn"MATLAB function
    "sl_block_diagram"Block diagram
    "sl_library_file"Library file
    "sl_model_file"Simulink model file
    "sl_protected_model_file"Protected Simulink model file
    "sl_subsystem"Subsystem
    "sl_subsystem_file"Subsystem file

    System Composer™

    "zc_block_diagram"System Composer architecture
    "zc_component"System Composer architecture component
    "zc_file"System Composer architecture file
    Tests"harness_info_file"Harness info file
    "sl_harness_block_diagram"Harness block diagram
    "sl_harness_file"Test harness file
    "sl_test_case"Simulink Test™ case
    "sl_test_case_result"Simulink Test case result
    "sl_test_file"Simulink Test file
    "sl_test_iteration"Simulink Test iteration
    "sl_test_iteration_result"Simulink Test iteration result
    "sl_test_report_file"Simulink Test result report
    "sl_test_result_file"Simulink Test result file
    "sl_test_resultset"Simulink Test result set
    "sl_test_seq"Test Sequence
    "sl_test_suite"Simulink Test suite
    "sl_test_suite_result"Simulink Test suite result

    Example: "sl_model_file"

    Example: ["sl_model_file "zc_file"]

    List of licenses that the task requires, specified as a string array.

    Example: Licenses = ["matlab_report_gen" "simulink_report_gen"]

    Data Types: string

    Setting to require all licenses for task, specified as a numeric or logical 1 (true) or 0 (false). By default, all licenses in the Licenses property of the task are required for the task to run. Specify 0 (false) if the task can run without all licenses listed in the Licenses property.

    Example: AllLicenseRequired = false

    Data Types: logical

    Task description, specified as a string.

    Example: "This task runs myScript."

    Data Types: string

    Path to task documentation, specified as a string.

    Example: DescriptionCSH = fullfile(pwd,"taskHelpFiles","myTaskDocumentation.pdf")

    Data Types: string

    Output Arguments

    collapse all

    Task object, returned as a padv.Task object.

    For more information, see padv.Task.