Main Content

getCallback

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

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_spreadsheet.Rows" + newline + ...
"  textCell = getCell(sfa_spreadsheet,n,2);" + newline + ...
"  checkCell = getCell(sfa_spreadsheet,n,1);" + newline + ...
"  if checkCell.Value == 0" + newline + ...
"      addFlag(textCell,""warning"")" + newline + ...
"  end" + newline + ...
"end";

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

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_spreadsheet.Rows
       textCell = getCell(sfa_spreadsheet,n,2);
       checkCell = getCell(sfa_spreadsheet,n,1);
       if checkCell.Value == 0
           addFlag(textCell,"warning")
       end
     end'

Input Arguments

collapse all

Spreadsheet in the Safety Analysis Manager, specified as a Spreadsheet 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.

Output Arguments

collapse all

Callback code, returned as a character vector.

Version History

Introduced in R2024a