Execute Code When Loading and Saving Requirement Sets
You can use Requirements Toolbox™ callbacks to execute code when you load and save requirement sets. The
PostLoadFcn callback executes when you load the requirement set and
PreSaveFcn callback executes when you save the requirement set. You
can assign code to the callbacks to customize the requirement set load and save
Assign Code to Callbacks
You can assign code to the callbacks in the Requirements Editor or at the MATLAB® command line.
Assign Code to Callbacks in the Requirements Editor
To assign code to the
PreSaveFcn callbacks in the Requirements Editor:
Open your requirement set by clicking Open. Select the SLREQX file and click Open.
Select the requirement set in the Requirements Editor.
In the right pane, under Callbacks, select the PostLoadFcn or PreSaveFcn tab.
Enter your code in the box.
Alternatively, you can enter your code in a script. In the PostLoadFcn or PreSaveFcn tab, enter the name of the script. The script must be on the MATLAB path.
Assign Code to Callbacks Programmatically
To assign code to the
PreSaveFcn callback at the MATLAB command line:
In MATLAB, select the Home tab, then click New Script.
In the script, enter the code that you want the callback to execute.
Select the Editor tab, then click Save. Enter a name for the script, then click Save.
Load your requirement set and return the
slreq.ReqSetobject by using
Assign the script as the
PreSaveFcncallback by using
You can view the code assigned to the
PreSaveFcn callbacks by using
Customize Requirement Set Load and Save Behavior
You can use the code assigned to callback to customize the requirement set load and
save behavior. For example, you can use the
Load the Requirements Editor view settings from a MAT-file by using
Open a design artifact, such as a Simulink® model or MATLAB script, by using
Run linked tests by using
You can also, for example, use
PreSaveFcn to export
the current Requirements Editor view settings to a MAT-file by using
You can use
slreq.getCurrentObject in the
PreSaveFcn callbacks to get a handle to the requirement set
within the callbacks. For more information, see the Tips section of