Main Content

Use Simulink Report Explorer Components in Report API Reports

The RptFile reporter lets you use Simulink® Report Explorer components in a Report API-based report program. This reporter is useful if your report program needs to generate content for which a Report Explorer component exists but for which no Report API reporter is available. For example, the Report Explorer includes a component named Block Type Count that generates the number of each type of block that a model contains. No equivalent Report API reporter exists.

This example shows how to use the RptFile reporter to include a count of the types of blocks used in the f14 Simulink model. This information is obtained from the Report Explorer Block Type Count component and is presented in tables in the generated Report API report.

Create Report Explorer Setup Files

Create a Report Explorer setup file that includes a Block Type Count component. For information about creating a report setup file, see Report Setup.

  1. Type report to open the Report Explorer.

  2. In the panel on the right, click Create and edit a Report file. Save the file as mysetupfile.rpt.

  3. From the Simulink folder in the middle panel, add a Model Loop component to your report. Set the Model name to Current block diagram.

  4. From the Simulink folder in the middle panel, add a System Loop component as a child of the Model Loop. Set these options:

    • Loop on SystemsSelect systems automatically

    • Include subsystems in Simulink functions — selected

    • Sort SystemsBy system depth

  5. From the Simulink folder in the middle panel, add a Block Type Count component as a child of the System Loop. Set these options:

    • Table title — Block Type Count

    • Show block names in title — selected

    • Sort tableAlphabetically by block type

  6. Save the file.

The mysetupfile.rpt hierarchy is

Hierarchy of mysetupfile.rpt file, with Report Generator at the top, followed by Report - my setupfile.rtp, Model Loop - current model, System Loop - Reported systems in current model, and Blocktype Count

Create Report Generator Programs

These steps describe how to create a Report Generator program that includes a RptFile reporter for the mysetupfile.rpt Report Explorer setup file.

Note

The full program is listed after the steps.

  1. To eliminate the need to use fully-qualified names of the report, finder, and utility functions, import the API functions. For example, instead of using mlreportgen.report.TitlePage, you can use TitlePage.

    import slreportgen.report.*
    import slreportgen.finder.*
    import mlreportgen.report.*
    import mlreportgen.utils.*
    

  2. Load the f14 model.

    model = "f14";
    openExample(model);
    

  3. Create a report object to hold the contents of the report. Use a Simulink report constructor (slreportgen.report.Report) to create a report object You must fully qualify the name of the constructor to distinguish it from the MATLAB® report constructor (mlreportgen.report.Report). Specify the name of the report as "My Report" and the output type as PDF.

    rpt = slreportgen.report.Report("MyReport","pdf");
    

  4. Add a title page and table of contents to the report.

    titlepg = TitlePage();
    titlepg.Title = "f14 Model Block Types ";
    titlepg.Author = "MathWorks";
    add(rpt,titlepg);
    
    toc = TableOfContents;
    add(rpt,toc);
    

    Title page showing title f14 Model Block Types, author MathWorks, and date 10 December 2018

    Table of contents showing 6 chapters

  5. Find all systems in the model.

    sysdiag_finder = SystemDiagramFinder(model);
    found_diags = find(sysdiag_finder);
    
  6. Use a for loop to create a separate chapter for each system and include a system snapshot with a single-line caption.

    Create a RptFile reporter based on mysetupfile.rpt. The reporter generates a table of block type counts for the current system. Add the RptFile reporter to the chapter and add the chapter to the report.

    for sysdiag = found_diags
        chap = Chapter(sysdiag.Path);
    
        snapshot = Diagram(sysdiag.Path);
        oneline = makeSingleLineText(sysdiag.Name);
        snapshot.Snapshot.Caption = strcat...
          ("System Diagram: ",oneline);
        add(chap,snapshot); 
    
        rptFile = RptFile("mysetupfile.rpt");
        rptFile.Model = model;
        rptFile.System = sysdiag.Path;
    
        add(chap,rptFile);
        add(rpt,chap);
    end

    The first time this loop runs during report generation, a snapshot and block count of the top-level system of the model is added to the report.

    Snapshot of model displaying under Chapter 1 heading

  7. Close and view the report.

    close(rpt);
    rptview(rpt);
    

The full program is

import slreportgen.report.*
import slreportgen.finder.*
import mlreportgen.report.*
import mlreportgen.utils.*

model = "f14";
openExample(model);

rpt = slreportgen.report.Report("MyReport","pdf");

titlepg = TitlePage();
titlepg.Title = "f14 Model Block Types ";
titlepg.Author = "MathWorks";
add(rpt,titlepg);

toc = TableOfContents;
add(rpt,toc);

sysdiag_finder = SystemDiagramFinder(model);
found_diags = find(sysdiag_finder);
for sysdiag = found_diags
    chap = Chapter(sysdiag.Path);

    snapshot = Diagram(sysdiag.Path);
    oneline = makeSingleLineText(sysdiag.Name);
    snapshot.Snapshot.Caption = strcat...
      ("System Diagram: ",oneline);
    add(chap,snapshot); 

    rptFile = RptFile("mysetupfile.rpt");
    rptFile.Model = model;
    rptFile.System = sysdiag.Path;
    add(chap,rptFile);

    add(rpt,chap);
end

close(rpt);
rptview(rpt);