主要内容

Create and Select Custom Callbacks for Safety Analysis Manager Fault Tree Documents

R2026b
Since R2026b

You can customize the code that executes in Safety Analysis Manager fault tree document callbacks by specifying custom callbacks. You create the callback, enable or disable it, and add the code.

Create Custom Callbacks

To create a custom callback that optionally executes when you analyze your fault tree documents:

  1. Open or create a new Safety Analysis Manager fault tree document. For more information on creating fault tree documents, see the Create Fault Trees in the Safety Analysis Manager.

  2. In the Analyze section, click Edit Callbacks. The Callbacks Editor window opens.

  3. In the Callbacks Editor window, point to the AnalyzeFcn callback and click the Add a new custom callback button .

    • To edit the name, double-click the callback and enter the new name. You must use a name that follows the naming conventions for variables in MATLAB®.

  4. Write the callback code. For more information on writing callbacks, see the Write Callbacks to Analyze Safety Analysis Manager Fault Tree Documents.

To execute the callback, expand Analyze Document and select the custom callback. When you click Analyze Document again, the Safety Analysis Manager runs the custom callbacks that you select.

Programmatically Create Custom Callbacks

You can also create and modify custom callbacks programmatically. To add a callback:

  1. Retrieve the FaultTreeDocument object from the Safety Analysis Manager by using the safetyAnalysisMgr.getOpenDocuments or safetyAnalysisMgr.openDocument functions, or use the safetyAnalysisMgr.newDocument function to create a new FaultTreeDocument object.

  2. Add the custom callback by using the addCallback function.

  3. Assign code to the custom callback by using the setCallback function.

  4. Enable or disable the callback by using the enableCallback function.

For example, to assign a callback to a fault tree document that simulates a model named myModel, open only one fault tree document and then run this code:

myFaultTreeDocument = safetyAnalysisMgr.getOpenDocuments;
addCallback(myFaultTreeDocument,"myNewCallback")
setCallback(myFaultTreeDocument,"myNewCallback","sim(""myModel"")")

See Also

Topics