Main Content

getTextRanges

Class: slreq.LinkSet
Namespace: slreq

Get lines ranges that span multiple lines

Since R2022b

Description

cr = getTextRanges(myLinkSet,lines) returns the line ranges associated with the lines of code, lines, in the file associated with the link set specified by myLinkSet.

Note

You must open the file in the MATLAB® Editor before using this function.

example

cr = getTextRanges(myLinkSet,blockSID,lines) returns the code ranges associated with the lines in the MATLAB Function block specified by blockSID.

Note

You must open the model in Simulink® before using this function.

example

Input Arguments

expand all

Link set, specified as an slreq.LinkSet object.

Start and end line numbers for the line range, specified as a double array of the form [start end] or a scalar double.

Example: [1 4], 1

MATLAB Function block SID, specified as a string scalar or character vector.

Example: "30"

Output Arguments

expand all

Line range, returned as an array of slreq.TextRange objects.

Examples

expand all

This example shows how to get slreq.TextRange objects in a link set.

Open the myAdd code file.

open("myAdd.m");

Get a handle to the myAdd link set.

myLinkSet = slreq.find(Type="LinkSet",Description="myAdd");

Get the slreq.TextRange object that corresponds to line number 3 in the file associated with the myAdd link set.

cr = getTextRange(myLinkSet(1),3);

You can also get the code ranges by using getTextRanges.

This example shows how to get slreq.TextRange objects in MATLAB Function blocks for link sets.

Open the myAddModel Simulink® model.

model = "myAddModel";
open_system(model);

Get the SID of the MATLAB Function block.

block = "myAddModel/MATLAB Function";
SID = get_param(block,"SID")
SID = 
'8'

Get a handle to the myAddModel link set.

myLinkSet = slreq.find(Type="LinkSet",Description="myAddModel");

Get the slreq.TextRange object associated with the first line of the MATLAB Function block.

cr = getTextRange(myLinkSet,SID,1);

You can also get the slreq.TextRange object by using getTextRanges.

Tips

Version History

Introduced in R2022b