Main Content

Reporting on DocBlock Blocks

This example shows how to include the contents of Simulink DocBlock blocks in a Microsoft® Word report generated by the Report API. The example model, slreportgen_demo_docblock, contains only DocBlock blocks, with one block for each kind of DocBlock document type:

  • RTF

  • HTML

  • Text

In the generated report, the contents of the DocBlock blocks look like this:

Import the API packages so that you can refer to API classes by their unqualified names, that is, without the names of the class packages in which they reside.

import mlreportgen.report.*
import slreportgen.report.*
import slreportgen.finder.*
import mlreportgen.dom.*

Load the model for this example.

model = 'slreportgen_demo_docblock';
load_system(model);

Create a container to hold the report content. To avoid a compilation error due to the model containing only virtual blocks, set the CompileModelBeforeReporting property of the report object to false.

rpt = slreportgen.report.Report('ModelDoc', 'docx');
rpt.CompileModelBeforeReporting = false;

Add a title page and table of contents.

add(rpt,TitlePage('Title',sprintf('%s Model Documentation',model)));
add(rpt,TableOfContents);

Find and loop through all the systems in the model.

finder = SystemDiagramFinder(model);
for system = find(finder)

Create a chapter for each system. Include the system name in the chapter title. Use the chapter to report on the DocBlock content of the system.

    ch = Chapter('Title',sprintf('System %s', system.Name));

Find all the DocBlock blocks in the current system. Each result returns the DocBlock reporter for the found DocBlock. The add method invokes the DocBlock reporter.

    docBlockFinder = BlockFinder(system);
    docBlockFinder.Properties = {'MaskType', 'DocBlock'}';
    results = find(docBlockFinder);
    if ~isempty(results)
        add(ch, results);
        else
        add(ch, "This system does not have documentation.");
    end
    add(rpt,ch)
end 

Close and view the report.

close(rpt);
close_system(model);
rptview(rpt);

See Also

| | | |

Related Topics