Main Content


Get number of hierarchy levels in block path



length = getLength(bp) returns a numeric value that corresponds to the number of levels in the model reference hierarchy for the block path.


collapse all

Open the project named ModelReferenceHierarchy.


The project opens a model hierarchy with sldemo_mdlref_depgraph as the top model.

Create a Simulink.BlockPath object that represents a block in the model hierarchy.

bp = Simulink.BlockPath(...
    'sldemo_mdlref_heater/Fahrenheit to Celsius'});

Get the number of hierarchy levels in the block path for the Simulink.BlockPath object.

length = getLength(bp)
length = 2

Input Arguments

collapse all

Fully specified block path, specified as a Simulink.BlockPath or Simulink.SimulationData.BlockPathobject. This block path uniquely identifies a block within a model hierarchy, even when the model hierarchy references the same model multiple times.

Output Arguments

collapse all

Length of the block path, returned as an integer. The length is the number of levels in the model reference hierarchy.

Version History

Introduced in R2010b