Documentation

slreportgen.finder.BlockFinder class

Package: slreportgen.finder
Superclasses:

Find Simulink blocks

Description

Finds blocks in a Simulink® diagram.

Construction

finder = BlockFinder(diagram) creates a finder that finds by default all types of blocks in the specified Simulink block diagram. To constrain the search to specific types of blocks, use the properties of the finder.

Note

This finder has two ways to find objects — find mode and iterator mode. In find mode, use its find method to return the results of a search as an array of results. Then, use a for loop to process the results. In iterator mode, use its hasNext and next methods to return the results of a search one at a time. Using these iterator methods, use a while loop to process the results. Neither of these methods has a performance advantage over the other, so use either mode depending on whether you prefer while or for loops.

finder = BlockFinder(Name,Value) sets properties using name-value pairs. You can specify multiple name-value pair arguments in any order. Enclose each property name in single quotes.

Input Arguments

expand all

See Container property.

Properties

expand all

Diagram in which to search, specified as one of these values:

  • Handle to a Simulink model or subsystem

  • Path to a Simulink model or subsystem

Type of block to find, such as Gain, specified as a string or character array, or a set of block types to find, specified as a string array or a cell array of character arrays.

Whether to include commented-out blocks in the search results, specified as a logical. If false, commented-out blocks are excluded from the search results.

Properties of objects to find, specified as a cell array of name-value pairs. The finder returns only objects that have the specified properties with the specified values.

Example: finder.Properties = {'Gain','5'}

Methods

results = find(finder) finds blocks in the diagram specified by the finder. This method returns the blocks it finds wrapped in result objects of type slreportgen.finder.BlockResult. To add tables of the block properties, add the results objects directly to the report or add them to a reporter that you then add to a report. The reports to which you can add the results of this method must be of reports of type slreportgen.report.Report

tf = hasNext(finder) determines if the diagram that the finder searches contains at least one block. If the diagram has at least one block, the hasNext method queues that block as the next block that the next method will return. The hasNext method then returns true. Use the next method to obtain that block. On subsequent calls, the hasNext method determines if the diagram has a block that the next method has not yet retrieved. It queues the block for the next method to retrieve and returns true. If there are no more blocks to be retrieved, this method returns false. To search a diagram progressively for blocks, use the hasNext method with the next method in a while loop.

result = next(finder) returns the next search result in the result queue that the hasNext method created. This method returns the block that it finds wrapped in a result object of type slreportgen.finder.BlockResult. To add tables of the block properties, add the result object to the report directly or add it to a reporter that you then add to a report. The reports to which you can add the results of this method must be of type slreportgen.report.Report.

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects (MATLAB).

Examples

Find Inport and Outport Blocks in a Model

Find Inport and Output blocks in the sf_car model.

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

model_name = 'sf_car';
load_system(model_name);
rpt = slreportgen.report.Report('output','pdf');

add(rpt,TitlePage("Title",...
     sprintf('I/O Blocks in %s Model', model_name)));
add(rpt,TableOfContents);

diagFinder = SystemDiagramFinder(model_name);
diagFinder.IncludeRoot = false;
while hasNext(diagFinder)
    diagram = next(diagFinder);
    chapter = Chapter("Title", diagram.Name);
    add(chapter,diagram);
    sect = Section("Title", "Inport Blocks");
    ioFinder = BlockFinder(diagram.Object);
    ioFinder.BlockTypes = "Inport";
    blocks = find(ioFinder);
    for block = blocks
        add(sect,block);
    end  
    add(chapter, sect);
    sect = Section("Title", "OutportBlocks");
    ioFinder = BlockFinder(diagram.Object);
    ioFinder.BlockTypes = "Outport";
    outblocks = find(ioFinder);
    for block = blocks
        add(sect,block);
    end  
    add(chapter,sect);
    add(rpt,chapter);
end
close(rpt);
close_system(model_name);
rptview(rpt);

Introduced in R2017b

Was this topic helpful?