Main Content

getCallback

R2026b

Retrieve spreadsheet callback code in Safety Analysis Manager

Since R2024a

Description

code = getCallback(spreadsheet,callbackType) returns the callback code for the callback, callbackType, in the Safety Analysis Manager spreadsheet, spreadsheet.

example

code = getCallback(faultTreeDocument,callbackType) returns the callback code for the callback, callbackType, in the Safety Analysis Manager fault tree document, faultTreeDocument. (since R2026b)

example

Examples

collapse all

Suppose you have one Safety Analysis Manager spreadsheet open, mySpreadsheet.mldatx, and it has two columns. The first is a check box column and the second is a text column. You want to write a callback script where, if the check box for a cell is not selected, you mark the adjacent cell in the text column with a warning flag.

Retrieve the Spreadsheet object of the spreadsheet.

mySpreadsheet = safetyAnalysisMgr.getOpenDocuments;

Create the callback code as a string.

callBackString = "for n = 1:sfa_document.Rows" + newline + ...
"  textCell = getCell(sfa_document,n,2);" + newline + ...
"  checkCell = getCell(sfa_document,n,1);" + newline + ...
"  if checkCell.Value == 0" + newline + ...
"      addFlag(textCell,""warning"");" + newline + ...
"  end" + newline + ...
"end";

The code uses the sfa_document keyword to retrieve the Spreadsheet object of the spreadsheet that contains this script.

Before R2026b: To retrieve the Spreadsheet object in a Safety Analysis Manager callback, use the sfa_spreadsheet keyword.

Assign the code to the default AnalyzeFcn callback by using the setCallback function.

setCallback(mySpreadsheet,"AnalyzeFcn",callBackString)

Retrieve the callback that you assigned.

getCallback(mySpreadsheet,"AnalyzeFcn")
ans =

    'for n = 1:sfa_document.Rows
       textCell = getCell(sfa_document,n,2);
       checkCell = getCell(sfa_document,n,1);
       if checkCell.Value == 0
           addFlag(textCell,"warning");
       end
     end'

Since R2026b

Suppose you have one Safety Analysis Manager fault tree document open, mySpreadsheet.mldatx. You want to check that each event in the fault tree document uses a unique failure model. If the assigned failure model is not shared, add a check flag to the event. If the assigned failure model is shared, add an error flag to the event.

Retrieve the FaultTreeDocument object of the fault tree document.

myFaultTreeDoc = safetyAnalysisMgr.getOpenDocuments;

Create the callback code as a string.

callBackString = "for n = 1:numel(sfa_document.Events)" + newline + ...
"   checkEvent = sfa_document.Events(n);" + newline + ...
"   if sfa_document.Events(n).FailureModel.Shared == 0" + newline + ...
"       addFlag(sfa_document.Events(n),""check"")" + newline + ...
"   else" + newline + ...
"       addFlag(sfa_document.Events(n),""error"")" + newline + ...
"    end" + newline + ...
"end";

Assign the code to the default AnalyzeFcn callback.

setCallback(myFaultTreeDoc,"AnalyzeFcn",callBackString)

Retrieve the AnalyzeFcn callback.

getCallback(myFaultTreeDoc,"AnalyzeFcn")
ans =

    'for n = 1:numel(sfa_document.Events)
        checkEvent = sfa_document.Events(n);
        if sfa_document.Events(n).FailureModel.Shared == 0
            addFlag(sfa_document.Events(n),"check")
        else
            addFlag(sfa_document.Events(n),"error")
         end
     end'

Input Arguments

collapse all

Spreadsheet in the Safety Analysis Manager, specified as a Spreadsheet object.

Fault tree document in the Safety Analysis Manager, specified as a FaultTreeDocument object.

Callback type to retrieve the code from, specified as one of these values:

Callback TypeWhen Callback Executes
"PreloadFcn"Before the spreadsheet loads
"PostloadFcn"After the spreadsheet loads
"AnalyzeFcn"When you use the runAnalysis function or press F5. This corresponds to the default AnalyzeFcn callback. To get callback code for a custom callback, set callbackType to the custom callback name.
"PresaveFcn"Before the spreadsheet is saved
"PostsaveFcn"After the spreadsheet is saved
"CloseFcn"Before the spreadsheet is closed
Custom callback nameIf the custom callback is enabled, it executes when you use the runAnalysis function or press F5. Create the custom callback by using the addCallback function.

In R2026a: The noncustom callback types are case insensitive.

Output Arguments

collapse all

Callback code, returned as a character vector.

Version History

Introduced in R2024a

expand all