Main Content

slreportgen.finder.BlockFinder class

Package: slreportgen.finder

Find Simulink blocks

Description

Finds blocks in a Simulink® diagram.

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

Creation

Description

example

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 two ways to get search results:

  1. 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.

  2. 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.

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.

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 slrgex_sf_car model.

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

model_name = "slrgex_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="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