Main Content

padv.util.closeModelsLoadedByTask

Close models loaded by task

    Description

    padv.util.closeModelsLoadedByTask(PreviouslyLoadedModels = modelList) closes models that were loaded by the current task. The function determines which models the task loaded by comparing the current list of loaded models to a list of previously loaded models, modelList. The function uses close_system(model,0) to close the models without saving.

    Use this function inside the run function of a custom task to close models loaded by the task. Note that the function does not close models that are open in the Simulink® Editor.

    This functionality requires CI/CD Automation for Simulink Check.

    example

    Examples

    collapse all

    Find which models were already loaded and then use the function padv.util.closeModelsLoadedByTask to close only models loaded by the current task.

    Inside the run function for your custom task, use the function get_param to find and save a list of the previously loaded models. Then, after your task performs its action and specifies the task results, close the models loaded by the task. For example, the run function in your custom task might look like:

        function taskResult=run(obj, input)
            % Before the task loads models, save a list of the models that are already loaded.
            loadedModels = get_param(Simulink.allBlockDiagrams(), 'Name');
     
            % <load models for this task>
            % <specify task results>
     
            % Close models that were loaded by this task.
            padv.util.closeModelsLoadedByTask(PreviouslyLoadedModels=loadedModels);
        end

    Input Arguments

    collapse all

    List of previously loaded models, specified as an array of model names.

    You can use the function get_param to find the currently loaded models:

    loadedModels = get_param(Simulink.allBlockDiagrams(), 'Name');

    Example: {'modelA';'modelB';'modelC'}