Programmatically copying requirement links from one Simulink block to another
15 views (last 30 days)
Show older comments
MathWorks Support Team
on 18 Jul 2022
Answered: MathWorks Support Team
on 5 Aug 2022
How do I programmatically copy the requirement links from one Simulink block to another?
Accepted Answer
MathWorks Support Team
on 18 Jul 2022
Suppose in a model 'myModel', you want to copy the requirement links 'scrReqLinks' from 'SourceBlock' to 'DestinationBlock'. There are two methods to achieve this workflow and the choice of the method depends upon the storage format of your requirement links.
If the requirements/link information is stored as an external file, you should use the 'slreq' commands to achieve the desired workflow. This is demonstrated by the following MATLAB script:
scrReqLinks = slreq.outLinks('myModel/SourceBlock'); %Get requirement links for SourceBlock
DestStore = destination(scrReqLinks); %Copy the requirement links to a buffer variable DestStore
destReqLinks = slreq.createLink('myModel/DestinationBlock', DestStore); %Create requirement links for Block B pointing towards DestinationBlock
Please note that this procedure will copy the requirements link but not the other properties of the link object. If required, the other properties need to be copied separately. For example: the following code snippet copies the 'description' and the 'rationale' properties' from 'scrReqLinks' to 'destReqLinks'.
destReqLinks.Description = scrReqLinks.Description;
destReqLinks.Rationale = scrReqLinks.Rationale;
On the other hand, if the requirements/link information is stored in the legacy 'RequirementInfo' format, the 'slreq' commands will not work. In this case, you will need to use the 'Requirements Management Interface' to achieve the desired workflow, as demonstrated by the following MATLAB script:
srcReqLinks = rmi('get', 'myModel/SourceBlock'); %Get requirement links for SourceBlock
rmi('set', 'myModel/DestinationBlock', srcReqLinks); %Set requirement links for DestinationBlock
For R2017b and later releases, we recommend storing the requirements/link information as an external file and not using the 'RequirementInfo' format. If you open a model that uses the legacy 'RequirementInfo' format, a notification banner should pop up and offers to convert the legacy storage format to the newer external file format.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!