Hiding container of a mask using callback/dynamically
6 次查看(过去 30 天)
显示 更早的评论
I am working to create a dynamic mask for a subsystem (refer image below).
I want to hide Specification 2- Specification 7 using callback (or any other method) in mask if "No. of models" is "1".
I cannot hide it like other mask parameters such as Voc1 using callback (refer code).
Please suggest how to proceed.
0 个评论
回答(1 个)
Rajanya
2024-9-18
I understand that you are trying to control the visibility of containers based on a popup parameter value. I was able to create a dummy mask like your custom mask with two containers (with names ‘Container3’ and ‘Container4’ under the prompt of ‘Specification1’ and ‘Specification2’ respectively) and a popup field (‘No. of models’) which can get populated with values 1 and 2 as shown below:
Containers, unlike mask parameters, need to be accessed by the ‘getDialogControl’ method from the ‘Simulink.dialog.Container’ class. For this, a mask object must be created first, like:
maskobj = Simulink.Mask.get(gcb);
The container properties can then be accessed via:
maskobj.getDialogControl(<container_name>);
The code below demonstrates how to control the visibility of ‘Specification1’ based on the popup parameter value with name ‘Parameter1’ and prompt ‘No. of models’. It hides ‘Specification1’ when ‘No. of models’ is anything other than 1.
selectedVal = get_param(gcb,'Parameter1')
if strcmp(selectedVal,'1')
maskobj.getDialogControl('Container3').Visible = 'on';
else
maskobj.getDialogControl('Container3').Visible = 'off';
end
You can also modify the ‘OpenFcn’ callback parameter of the block under Properties > Callbacks > OpenFcn accordingly in a similar fashion to add a callback functionality to the subsystem.
Refer to the following resources for more information:
‘getDialogControl’ for Container classes-https://www.mathworks.com/help/releases/R2021a/simulink/slref/simulink.dialog.container.getdialogcontrol.html
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Author Block Masks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!