How to close block dialog box before it opens or hide it conditionally on Simulink?

3 views (last 30 days)
Hello,
I am trying to create a custom masked block, but when some conditions met -defined in callback script- I don't want the block dialog box not to open at all.
I have tried to do this from the callback script but got no results because block dialog box always open after script completely executed, actually at this point I feel like my hands are tied. I have also tried to change block callbacks, still no success.
Any help would be appreciated, thanks in advance!
  2 Comments
Fangjun Jiang
Fangjun Jiang on 20 Nov 2018
Providing an example would be helpful. What callback function did you put in? What two conditions and scripts you have now that would open or not open the block dialog?
Burak Bayram
Burak Bayram on 21 Nov 2018
Edited: Burak Bayram on 21 Nov 2018
Alliright, so the callback function contains switch and case functions regarding parameters of masked block. nothing to explain detailly, function goes like;
function varargout = myblock_m(block, action)
switch action;
case 'initialization'
..
case 'mask_callback_a' % callback of the parameter 'a' of 'myblock' masked block.
..
..
..
end
end
So in some cases script will open the Scope inside the masked block and display it in the screen, in this cases I want dialog box of masked block not to open at all. So firstly, I tried to write this;
case 'mask_callback_a'
..
..
if condition met
open_system(find_system(gcb, 'LookUnderMasks','all','BlockType','Scope'));
close_system(gcb) %So here I want dialog box to close, but of course right now
% there is no dialog box to begin with because script didn't completely
% executed yet and this will end up with crash.
end
..
..
So luckily after I ask this question, some hours later I came up with a solution which is not optimal and smooth but works; OpenFcn block callback. Where I can conditionally open and close the mask(block dialog box for my case) not depending on callback script the execute completely because after that I can just write close_system(gcb, 'mask') to the next line.
But as I said it was not so smooth, and comes with few problems;
  1. If you write any word on OpenFcn Callback function, the block callbacks of parameters will not work at all. If you want them to you need to wirte them exclusively.
  2. If you don't write them at OpenFcn, and I don't feel safe about this frankly.
  3. Workspace problem, so my masked blocks callback scripts have another workspace and only interacts with base workspace so if I want it to interact callback script with OpenFcn I needed to use base workspace which is not optimal beacuse variables always written on workspace and they can be changed from command window easily, this block as all blocks should have been working silently in the back.
So for the last problem I tried to use modelworkspace which is not helped much because even if I assign values to the modelworkspace on OpenFcn it still saves on base workspace...
At this moment I have achieved the functionalities I wanted, when my conditions met block dialog box closes and can be opened when another met. But now there is this little problem of workspace because I can not hide my blocks variables at base workspace.
So I hope my solution help to another people having similiar problem but, if you have better approach or solutions to my ongoing problems I am all ears!

Sign in to comment.

Answers (0)

Products


Release

R2015b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!