Main Content

Simulink.BlockDiagram.routeLine

Route existing lines of model

Description

example

Simulink.BlockDiagram.routeLine(lines) takes an array of existing line handles as input and routes the corresponding lines. Routing existing lines improves line route quality and avoids overlaps with other lines and obstacles in the model.

To find the line handles in the model you want to route, use the find_system or get_param function.

example

Simulink.BlockDiagram.routeLine('DeferredLines') performs all line updates that the LineUpdate model parameter defers while a script runs. For this command to route lines, all of these conditions must apply:

  • The LineUpdate model parameter is set to 'deferred'.

  • The script that contains this command affects line routing before using this command.

  • If the script saves models, the script affects line routing after using the save_system function and before using this command.

Examples

collapse all

Route existing lines of a model that overlap with other lines and blocks in the model.

Open the model ex_route_lines.

open_system('ex_route_lines');

The two lines in the top-level system overlap with each other and with a block. To route these lines, create an array of line handles by using find_system. Then, call Simulink.BlockDiagram.routeLine with this array as input.

lineHandles = find_system(gcs,'FindAll','On','SearchDepth',1,'Type','Line');
Simulink.BlockDiagram.routeLine(lineHandles);

The updated model has no overlaps.

When the LineUpdate model parameter is set to 'deferred', scripts postpone line routing until they pause, complete, or run the Simulink.BlockDiagram.routeLine('DeferredLines') command.

Model ex_route_deferred_lines contains virtual subsystems with numerous signal lines connecting them.

To see how the Simulink.BlockDiagram.routeline('DeferredLines') command works with the LineUpdate model parameter, set this parameter to 'deferred'.

set_param(0,'LineUpdate','deferred');

Capture Image Before Routing Deferred Lines

Run a MATLAB® script that loads the model, moves blocks within the model, and saves an image of the model.

load_system('ex_route_deferred_lines');
set_param([gcs '/Subsystem2'],'Position',[765 -370  855 -330]);
set_param([gcs '/Subsystem3'],'Position',[300  215  390  335]);
set_param([gcs '/Subsystem4'],'Position',[270 -135  360  -95]);
print('-s','deferred_lines_unrouted','-dpng');

Because the script saves an image of the model before the deferred lines are routed, lines overlap other lines and obstacles in the model.

Capture Image After Routing Deferred Lines

Run a MATLAB script that loads the original model, moves blocks within the model, updates affected line routing, and saves an image of the model.

load_system('ex_route_deferred_lines');
set_param([gcs '/Subsystem2'],'Position',[765 -370  855 -330]);
set_param([gcs '/Subsystem3'],'Position',[300  215  390  335]);
set_param([gcs '/Subsystem4'],'Position',[270 -135  360  -95]);
Simulink.BlockDiagram.routeLine('DeferredLines');
print('-s','deferred_lines_routed','-dpng');

Adding command Simulink.BlockDiagram.routeline('DeferredLines') before the print function improves line routing in the saved image.

Input Arguments

collapse all

Handles of lines to route, specified as a numeric array. To find the line handles in your model, use the find_system or get_param function.

Data Types: double

Limitations

  • Line routing can require additional empty space on the Simulink® canvas. If the canvas does not have the required empty space, using Simulink.BlockDiagram.routeLine might not improve line route quality.

  • For large models with many lines to route, Simulink.BlockDiagram.routeLine can take several minutes to execute.

Version History

Introduced in R2019a