Contenido principal

gcbp

R2026b

Get Simulink.BlockPath object for current block

Description

blockObj = gcbp returns the Simulink.BlockPath object of the current block in the current system. The returned Simulink.BlockPath object is context sensitive to model hierarchy.

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.

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

Note

Suppose a model contains multiple references to the same model. To set the same parameter to different values in each instance of the referenced model, use instance parameters. Using the Simulink.BlockPath object for this task is not supported. For more information about how to complete the task using instance parameters, see Parameterize a Referenced Model Programmatically.

example

Examples

collapse all

Suppose you have a model named myModel1 that is open in Simulink®. The model contains two Model blocks, named myRef1 and myRef2. Both reference the same model, named myModel2. The reference model contains a Constant block named myConst. Create a Simulink.BlockPath object for the Constant block in myRef1.

Use your pointer to select the Constant block in myRef1.

Create a Simulink.BlockPath object for the selected block.

inst = gcbp
inst = 
  Simulink.BlockPath
  Package: Simulink

  Block Path:
    myModel1/myRef1
      myModel2/myConst

  Use the getBlock method to access block path strings from this object.

  Methods

Output Arguments

collapse all

Simulink.BlockPath object of the current block in the current system.

Version History

Introduced in R2019a