Contenuto principale

Simulink.BlockDiagram.resizeBlocksToFitContent

R2026b

Adjust block size to fit displayed value

Since R2024b

    Description

    resizedBlocks = Simulink.BlockDiagram.resizeBlocksToFitContent(sys) resizes blocks of these types in the specified model, library, or subsystem to be large enough to fit the parameter value they display on their block icons:

    When the blocks are too small to display the parameter value, the blocks display a placeholder letter instead, for example, -K-.

    The Simulink.BlockDiagram.resizeBlocksToFitContent function does not act on blocks in model references.

    example

    resizedBlocks = Simulink.BlockDiagram.resizeBlocksToFitContent(sys,ReportOnly="true") identifies the same blocks as the first syntax, but instead of resizing the blocks, this syntax outputs the block paths, specified as a cell array of character vectors.

    resizedBlocks = Simulink.BlockDiagram.resizeBlocksToFitContent(sys,BlockList=blocksToResize) resizes all blocks in the specified list according to the same rules as the first syntax and outputs their block paths, specified as a cell array of character vectors.

    Examples

    collapse all

    This example shows how to programmatically resize all value-displaying blocks in a model to be large enough to display their values instead of placeholder letters.

    Open the sldemo_hardstop_resized model.

    model = "sldemo_hardstop_resized";
    open_system(model);

    At the top level of the model, the Gain block named Kspring and the Constant block named Normal Force are too small to display their values. Instead, the blocks respectively display the placeholder letters -K- and -C-. Programmatically select the blocks so that you can see where the blocks are located in the model.

    set_param(model+"/Kspring",Selected="on");
    set_param(model+"/Normal Force",Selected="on");

    Open the Friction Model subsystem.

    subsys = model+"/Friction Model";
    open_system(subsys);

    In the subsystem, the Gain blocks named Mu Static and Mu Kinetic are too small to display their values. Instead, the blocks display -K-.

    set_param(subsys+"/Mu Static",Selected="on");
    set_param(subsys+"/Mu Kinetic",Selected="on");

    Get the names of all the blocks that are too small to display their values.

    resizedBlocks = Simulink.BlockDiagram.resizeBlocksToFitContent(model,ReportOnly="true")
    resizedBlocks = 4×1 cell
        {'sldemo_hardstop_resized/Friction Model/Mu Kinetic'}
        {'sldemo_hardstop_resized/Friction Model/Mu Static' }
        {'sldemo_hardstop_resized/Kspring'                  }
        {'sldemo_hardstop_resized/Normal Force'             }
    
    

    Resize only the blocks in the subsystem named Friction Model that are too small to display their values. Use the find_system function to get the paths of the blocks in the subsystem.

    blocks = find_system(subsys);
    Simulink.BlockDiagram.resizeBlocksToFitContent(model,BlockList=blocks);

    Check the blocks again. The blocks in the subsystem now display values, but the blocks at the top level of the model still display placeholder letters.

    Resize all the blocks in the model that are too small to display their values.

    Simulink.BlockDiagram.resizeBlocksToFitContent(model);

    All blocks now display values instead of placeholder letters.

    Input Arguments

    collapse all

    Model, library, or subsystem in which to resize blocks. Specify a model or library as a name, and specify a subsystem as the block path of the corresponding Subsystem block. Format the name or path as a string or character vector.

    For information about getting block paths, see Get Handles and Paths.

    Example: "myModel"

    Example: "myModel/mySubsystem"

    Data Types: string | character vector

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: Simulink.BlockDiagram.resizeBlocksToFitContent(model,ReportOnly="true")

    Option to report block paths but not replace blocks, specified as "false" or "true". When ReportOnly is true, the function outputs the paths of all blocks in the specified model or from the specified list of blocks that display placeholder names but does not resize any blocks. When ReportOnly is false, the function outputs the same block paths and resizes the blocks.

    Data Types: string | character vector

    Set of blocks to resize, specified as block paths. Format the paths as a string, string array, character vector, or cell array of character vectors.

    For information about getting block paths, see Get Handles and Paths.

    Example: ["myModel/myBlock1","myModel/myBlock2"]

    Data Types: string | string array | character vector | cell array of character vectors

    Output Arguments

    collapse all

    Resized blocks, returned as block paths specified as a cell array of character vectors.

    Data Types: double | array of doubles

    Version History

    Introduced in R2024b