Main Content

gcb

R2026b

Get path name of current block

Description

blockPath = gcb returns the path of the current block in the current system.

The current block is:

  • The most recently clicked block; when you select multiple blocks using a selection box, it is the first block that gets selected

  • The S-Function block currently running its MATLAB® function

  • When a callback is invoked, the block invoking the callback; the current block can change during the execution of the callback, for example if you set breakpoints or interact with an editor.

  • The block whose mask is being evaluated as part of the MaskInitialization parameter evaluation, provided the mask initialization code does not change the current block

  • The last block loaded after opening a model

The current system is one of these:

  • During editing, the most recently clicked subsystem or the subsystem that contains the most recently clicked block; if the most recent click is in the top level of the model hierarchy, the current system is the model.

  • During simulation of a model that contains an S-Function block, the subsystem containing the S-Function block currently being evaluated; if the S-Function being evaluated is in the top level of the model hierarchy, the current system is the model.

  • When a callback is invoked, the model, subsystem, or block invoking the callback; the current system can change during the execution of the callback, for example if you set breakpoints or interact with an editor.

  • During evaluation of the MaskInitialization function, the subsystem containing the block whose mask is being evaluated; if the mask is in the top level of the model hierarchy, the current system is the model.

  • The model most recently loaded into memory with the load_system function.

    If you load a model using the load_system function and then change the current system, loading the model a second time using the load_system function does not make the model the current system. To make the model the current system, close the model and then reload the model using the load_system function.

Use the gcs function to determine the current system.

example

blockPath = gcb(sys) returns the path of the current block in the specified system. To use this syntax, the system must be loaded.

example

Examples

collapse all

Suppose the current block is a Gain block.

Get the gain value of the current block.

get_param(gcb,"Gain")

Suppose you have a model named myModel that is open in Simulink®. The model contains a Subsystem block named mySubsystem that contains a Gain block named myBlock. Suppose the Gain block is selected, and the current system is the subsystem. Get the path of the current block, then get the path of the current block in the top level of the model and compare the results.

Get the path of the current block in the current system.

gcb
ans =
    'myModel/mySubsystem/myBlock'

In the subsystem, the current block is the selected block.

Get the path of the current block in the top level of the model.

gcb("myModel")
ans =
    'myModel/mySubsystem'

In the top level of the model, the current block is the block that contains the selected block.

Input Arguments

collapse all

Model, library, or subsystem containing the block. Specify a model, library, or subsystem saved in its own file as a model name. Specify a subsystem in a model 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/mySubsystem"

Data Types: string | character vector

Output Arguments

collapse all

Path of current block, returned as a character vector.

Data Types: character vector

Version History

Introduced before R2006a