Main Content

slreportgen.finder.BlockFinder Class

Namespace: slreportgen.finder

Find Simulink blocks

Description

Finds blocks in a Simulink® diagram.

The slreportgen.finder.BlockFinder class is a handle class.

Creation

Description

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 provides these options to get search results:

  • To return the search results as an array, use the find method. Add the results directly to a report or process the results in a for-loop.

  • To iterate through the results one at a time, use the hasNext and next methods in a while-loop.

Neither option has a performance advantage.

example

finder = BlockFinder(Name=Value) sets properties using name-value arguments. You can specify multiple name-value arguments in any order.

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.

Variants of a variant block to include in the search results, specified as one of the values in the table. You can specify the value as a string scalar or a character vector.

ValueDescription
"Active"Active variants (default)
"All"All variants
"ActivePlusCode"Active variants and code variants

Number of levels to search Container, specified as a nonnegative integer or inf. Specify inf to search all levels.

Sorting method for finder results, specified as one of these values:

ValueDescription
"none"Do not sort results.
"alphabetical"Sort results alphabetically by name.
"systemAlpha"Sort results alphabetically by parent system name.
"fullPathAlpha"Sort results alphabetically by full path.
"blockType"Sort results alphabetically by type.
"depth"Sort results by depth in the model hierarchy. The first result in the sorted list belongs to the system that is highest in the hierarchy. For example, a result in the top-level model and blocks in subsystems are sorted in the order: myModel/block1, myModel/subsystem1/block2, myModel/subsystem1/nestedSubststem/block3.
"leftToRight"Sort results by their location in the model layout using rows from left to right. A row of blocks in the model is a subgroup of blocks that are positioned between two horizontal lines. A minimal row is a row that cannot be divided to subrows. The algorithm first groups the blocks into minimal rows and sorts each row from left to right. The algorithm then concatenates the sorted rows from top to bottom.
"topToBottom"Sort results by their location in the model layout using columns from top to bottom. A column of blocks in the model is a subgroup of blocks that are positioned between two vertical lines. A minimal column is a column that cannot be divided to subcolumns. The algorithm first groups the blocks into minimal columns and sorts each row from top to bottom. The algorithm then concatenates the sorted rows from right to left.
"runtime"Sort nonvirtual blocks by their order of execution in a model or nonvirtual subsystem. This option compiles the model containing the specified blocks. Any block result that represents a virtual block or a block that is not a part of the system specified by Container is appended to the end of the sorted block list. For multitasking systems, blocks are grouped by the task in which they execute.

Limit the search to blocks that are connected to a specific signal, specified as an slreportgen.finder.SignalResult object or port handle. If this property is empty, the search is not limited to blocks that are connected to specific signals.

Example: finder.ConnectedSignal = find_system(my_model,findall=true,type="port",name="my_signal")

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

expand all

Examples

collapse all

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="I/O Blocks in "+model_name+" Model"));
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="Outport Blocks");
    ioFinder = BlockFinder(diagram.Object);
    ioFinder.BlockTypes = "Outport";
    outblocks = find(ioFinder);
    for block = outblocks
        add(sect,block)
    end  
    add(chapter,sect)
    add(rpt,chapter)
end
close(rpt)
close_system(model_name)
rptview(rpt)

Version History

Introduced in R2017b