Main Content

Running Clone Detection Custom Script in a Project

This example shows how to run a custom script for detecting clones on the set of Simulink® model files managed in a project. Creating a custom script would help to organize and automate the large modeling projects. For more information on setting up a custom task, see Run Custom Tasks with a Project.

This example shows how to create and run a custom script to automate the clone detection across all the models in a Simulink project. For more information on clone detection, see Enable Component Reuse by Using Clone Detection.

This example uses the Airframe project to demonstrate the working of clone detection across multiple models.

1. Open the Airframe project and use currentProject to get a project object.

    project = currentProject;
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.

2. Use the Simulink.CloneDetection.Settings class to create an object for find clones operation. Add the path of the RootFolder to cloneDetectionSettings object.

    cloneDetectionSettings = Simulink.CloneDetection.Settings();
    cloneDetectionSettings.Folders = project.RootFolder;

3. To find clones, execute the function Simulink.CloneDetection.findClones using the cloneDetectionSettings object.

    cloneResults = Simulink.CloneDetection.findClones(cloneDetectionSettings);

4. You can highlight the subsystem clone in a model using the function Simulink.CloneDetection.highlightClone.

    Simulink.CloneDetection.highlightClone(cloneResults, 'AnalogControl/Saturation Detection');

The clone results is an object of Simulink.CloneDetection.Results class. For detailed information on how to see the clone results, see Detect and Replace Subsystem Clones Programmatically.

Related Topics