User`s guide
25 Create Model Advisor Checks
25-12
'Text entry example'];
rec.setAction(myAction);
mdladvRoot.publish(rec, 'Demo');
% --- SimpleCallback function that checks constant blocks
function result = SimpleCallback(system)
mdladvObj = Simulink.ModelAdvisor.getModelAdvisor(system);
result = {};
all_constant_blk=find_system(system,'LookUnderMasks','all',...
'FollowLinks','on','BlockType','Constant');
blk_with_value=find_system(all_constant_blk,'RegExp','On','Value','^[0-9]');
ft = ModelAdvisor.FormatTemplate('ListTemplate');
ft.setInformation(['This check looks for constant blocks that'...
' use numeric values']);
if ~isempty(blk_with_value)
ft.setSubResultStatusText(['Check has failed. The following '...
'Constant blocks have numeric values:']);
ft.setListObj(blk_with_value);
ft.setSubResultStatus('warn');
ft.setRecAction('Parameterize the constant block');
mdladvObj.setCheckResultStatus(false);
mdladvObj.setActionEnable(true);
else
ft.setSubResultStatusText(['Check has passed. No constant blocks'...
'with numeric values were found.']);
ft.setSubResultStatus('pass');
mdladvObj.setCheckResultStatus(true);
end
ft.setSubBar(0);
result{end+1} = ft;
% --- creates SimpleActionCallback function that fixes failed check
function result = simpleActionCallback(taskobj)
mdladvObj = taskobj.MAObj;
result = {};
system = getfullname(mdladvObj.System);
% Get the string from the input parameter box.
inputParams = mdladvObj.getInputParameters;
textEntryEx = inputParams{1}.Value;
all_constant_blk=find_system(system,'LookUnderMasks','all',...
'FollowLinks','on','BlockType','Constant');
blk_with_value=find_system(all_constant_blk,'RegExp','On','Value','^[0-9]');
ft = ModelAdvisor.FormatTemplate('TableTemplate');
% Define table col titles
ft.setColTitles({'Block','Old Value','New Value'})
for inx=1:size(blk_with_value)
oldVal = get_param(blk_with_value{inx},'Value');
ft.addRow({blk_with_value{inx},oldVal,textEntryEx});
set_param(blk_with_value{inx},'Value',textEntryEx);