Main Content

addTaskTool

Add tool to help organize and complete task activities

    Description

    addTaskTool(pm,taskTool) adds a tool to the process model. You can use task tools to help you organize and complete task activities. Starting in R2024a, you can access the tools for a task by pointing to the task in the Tasks column in Process Advisor and opening the options menu (...).

    Task options menu showing a custom task app

    This functionality requires CI/CD Automation for Simulink Check.

    example

    Examples

    collapse all

    Starting in R2024a, you can integrate custom apps into your process model by using the addTaskTool function. You create the custom app by using App Designer or uifigure and represent the app by using a padv.TaskTool object. For this example, you add a custom app as a tool for a task and view the tool in the options menu for the task in Process Advisor.

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

    processAdvisorExampleStart

    Create a custom app for a task in the process.

    You can use App Designer to create a custom app that helps you complete activities for a task in your process. In the MATLAB® Command Window, open App Designer by entering:

    appdesigner
    Use the App Designer app to interactively develop an app. For this example, you can create and save a blank app. For more information, see App Designer.

    To use your App Designer app as a task tool, you must include a TaskContext property that you pass as a name-value argument in the constructor and your app must return a matlab.ui.Figure object during initialization. You can save your app as an App Designer app (.mlapp), export your App Designer app as an M file, or define your app by using a MATLAB class (.m). For example, the following MATLAB class defines a blank App Designer app that can be a task tool.

    classdef blankApp1 < matlab.apps.AppBase
        properties (Access = public)
            UIFigure  matlab.ui.Figure
            TaskContext
        end
        methods (Access = private)
            function createComponents(app)
                app.UIFigure = uifigure('Visible', 'on');
            end
        end
        methods (Access = public)
            function app = blankApp1(NameValueArgs)
                arguments
                    NameValueArgs.TaskContext
                end
                app.TaskContext = NameValueArgs.TaskContext;
                createComponents(app);
                if nargout == 0
                    clear app
                end
            end
            function delete(app)
                delete(app.UIFigure)
            end
        end
    end

    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 the following example code. the code defines:

    • myTask — A custom task.

    • myTaskTool — A custom tool for a task. The tool calls the function specified by the ToolFunction argument. In the Process Advisor context menu for a task, the tool has the title My Custom App. Since the tool function, blankApp1, is a .mlapp file for an App Designer app, the Type is set to TaskApp.

    Inside the process model, the code adds the task and tool to the process model and specifies the tool as one of the task tools for the task.

    function processmodel(pm)
        % Define process model for project
    
        arguments
            pm padv.ProcessModel
        end
    
        % --- Task ---
        myTask = padv.Task("MyCustomTask");
    
        % --- TaskTool ---
        myTaskTool = padv.TaskTool(ToolFunction="blankApp1",Title="My Custom App",...
            Type=padv.TaskToolType.TaskApp);
    
        % --- Integrate ---
        pm.addTask(myTask);
        pm.addTaskTool(myTaskTool);
        myTask.TaskTools = myTaskTool;
    
    end

    In Process Advisor, update the task information by clicking Refresh Tasks.

    In the Tasks column, point to MyCustomTask, open the options menu (...), and click My Custom App.

    The App Designer app opens inside Process Advisor. You can use your app to help organize and complete activities related to your tasks.

    Task options menu showing a custom task app

    Starting in R2024a, you can integrate custom commands into your process model by using the addTaskTool function. You represent the custom commands by using padv.TaskTool objects. For this example, you add two custom commands as tools for a task and view the tools in the options menu for the task in Process Advisor.

    Open the Process Advisor example project. The model AHRS_Voter opens with the Process Advisor pane to the left of the Simulink canvas.

    processAdvisorExampleStart

    Define your custom command by creating a new MATLAB function file. The function must accept a TaskContext as a name-value argument and must be on the MATLAB path.

    For this example, you can create a file named myCustomCommand.m and define a custom function that accepts and displays an input argument.

    function out = taskCmd1(inputArg, NamedValueArgs)
        arguments
        inputArg
        NamedValueArgs.TaskContext
        end
    
        disp(inputArg);
        
    end

    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 the following example code. the code defines:

    • myTask — A custom task.

    • myTaskTool — A custom tool for a task. The tool calls the function specified by the ToolFunction argument. In the Process Advisor context menu for a task, the tool has the title My Command 1. Since the tool function, taskCmd1, is a .m file for a function that defines a command for the task tool to execute, the Type is set to Command. The function accepts an input argument cmd1Arg.

    Inside the process model, the code adds the task and tool to the process model and specifies the tool as one of the task tools for the task.

    function processmodel(pm)
        % Define process model for project
    
        arguments
            pm padv.ProcessModel
        end
    
        % --- Task ---
        myTask = padv.Task("MyTask");
        pm.addTask(myTask);
        
        % --- TaskTool ---
        cmd1Arg = "myInputArg";
        myTaskTool = padv.TaskTool(ToolFunction="taskCmd1",...
            Title="My Command 1",...
            Type=padv.TaskToolType.Command,...
            Arguments={cmd1Arg});
    
        % --- Integrate ---
        pm.addTaskTool(myTaskTool);
        myTask.TaskTools = myTaskTool;
    
    end

    In Process Advisor, update the task information by clicking Refresh Tasks.

    In the Tasks column, point to MyTask, open the options menu (...), and click My Command 1.

    Process Advisor executes the command specified in the taskCmd1 function. The function displays the input argument, "myInputArg", in the MATLAB Command Window.

    Task options menu showing a custom command

    Input Arguments

    collapse all

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

    Example: pm = padv.ProcessModel

    Tool to help complete a task, specified as a padv.TaskTool object or an array of padv.TaskTool objects.

    Example: padv.TaskTool(ToolFunction="app1_exported",Title="My App",Type=padv.TaskToolType.TaskApp)

    Example: [padv.TaskTool(ToolFunction="app1_exported",Title="My App 1",Type=padv.TaskToolType.TaskApp),padv.TaskTool(ToolFunction="app2_exported",Title="My App 2",Type=padv.TaskToolType.TaskApp)]