Dynamically populating mask parameter popup list

14 ビュー (過去 30 日間)
Arun 2013 年 7 月 23 日
コメント済み: checker 2021 年 2 月 14 日
Is it possible to dynamically populate a Simulink mask's popup parameter's list using Dialog callback? Or is this facility static and to be defined while editing the mask?
  1 件のコメント
Kyle 2013 年 8 月 13 日
I would also like to know if this is possible



Arun 2013 年 8 月 14 日
Actually, I figured this out after hours of experimenting with Mask Parameters. This is one way to do it: You can access the 'MaskStyles' parameter like so:-
myMaskStylesVar = get_param(gcb, 'MaskStyles');
Here you should be able to observe the MaskStyles for each of your parameters as edit, checkbox, DataTypeStr, Minimum, Maximum or ...wait for it... popup! Yes, and 'popup' style is defined as follows:-
So you can modify the corresponding cell of myMaskStylesVar with the menu items of your choice and set them back as:-
myMaskStylesVar{1} = 'popup(red|green|blue|yellow)'; % Assuming the popup is the first parameter
set_param(gcb, 'MaskStyles', myMaskStylesVar)
You can add this code at any desired callback. In my case, I put it in 'OpenFcn'. However that led to another issue with the Mask Parameters Dialog not being invoked at the end of the code. So I had to do some crude workaround like below to invoke the Mask Parameter Dialog, but at the same time, not lose my precious code above!
a = get_param(gcb, 'OpenFcn');
set_param(gcb, 'OpenFcn', '');
open_system(gcb); %With no OpenFcn defined, this line will call Mask Parameter Dialog
set_param(gcb, 'OpenFcn', a); %Restore your original OpenFcn code
I am 99.99% sure this issue can be handled in a less comical way than above. But it works for me and my boss doesn't complain!! :)
  6 件のコメント
checker 2021 年 2 月 14 日
Jared, thanks buddy, that's awesome. I've moved from older versions of matlab to 2020 and have been finding lots of new APIs but this one eluded me until I ran across your post.


その他の回答 (2 件)

Kaustubha Govind
Kaustubha Govind 2013 年 8 月 14 日
I'm not much of an expert in the Simulink Mask area, but I don't think you can dynamically change the contents of a mask. However, you can change the visibility of parameters - so you might want to create multiple popup lists for each configuration and change their visibility in the Dialog Callback.
  2 件のコメント
Matthew 2016 年 11 月 18 日
編集済み: Matthew 2016 年 11 月 18 日
It turns out there is a simple DAStudio functionality that allows masks to be dynamic once open.
dToolRoot = DAStudio.ToolRoot;
openDialogs = dToolRoot.getOpenDialogs;
blockObject = get_param(gcb,'object');
blockDialog = DAStudio.Dialog(blockObject.getDialogSource);
I'll add a full code sample as an answer.


Matthew 2016 年 11 月 18 日
編集済み: Matthew 2016 年 11 月 18 日
If you want to update a popdown menu while a mask is open, the following may be helpful:
% Set the parameter index equal to the index specified
% for the desired popup parameter in the mask editor
parameterIndex = 1;
% Get the handle to the mask parameter to modify
maskHandle = Simulink.Mask.get(gcb);
maskParameters = maskHandle.Parameters;
% Update the popup list options
maskParameters(parameterIndex).TypeOptions = {'Option 1', 'Option 2'};
% Now refresh the mask display
%Get the handle to the blocks object
%Get the handle to the dialog
blockDialog= DAStudio.Dialog(blockObject.getDialogSource);
%Refresh the dialog
Note: Most of the DAStudio commands came from Christian in this answer.


Find more on Simulink Environment Customization in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by