Change visibility of a Paramter Based on variant selected on a masked susbsystem

7 views (last 30 days)
Hello All,
I have a variant subsystem with 2 Variants
  1. Variant A
  2. Variant B
The Variant is controlled by a Mask Parameter called VariantSelect.
In Variant A I have a parameter called TestParam
In Variant B I have a parameter called TestParam and TestParam2.
When I select a Variant A from masked susbsystem. I only want TestParam to be visible on the mask as the paramater.
When I select a Variant B from masked susbsystem. I only want TestParam and TestParam2 to be visible on the mask as the paramater.
My code in Callback of the mask
varObj = get_param(gcb, 'VariantSelect');
switch varObj
case 'Variant A'
maskObj = Simulink.Mask.get(gcb);
maskObj.set('TestParam', 'Visible', 'on');
maskObj.set('TestParam2', 'Visible', 'off');
case 'Variant B'
maskObj = Simulink.Mask.get(gcb);
maskObj.set('TestParam', 'Visible', 'on');
maskObj.set('TestParam', 'Visible', 'on');
end
The Selection of Variant works well but ,
Both the paramaters are shown all the time [if I check the visible Option in Parameter & Dialog --> Property Editor]
Please let me know, where it is going wrong
None of the paramaters are shown all the time [if I un-check the visible Option in Parameter & Dialog --> Property Editor]
Please let me know, where it is going wrong.

Answers (1)

Hitesh
Hitesh on 10 Apr 2025
Hi Abhishek,
In the code you have shared, within variant B, Line9 and Line10 are identical that is "TestParam" is set to visible twice. It needs to be "TestParam2" to ensure "TestParam2" is also visible for variant B. Please let me know if the issue persists. Additionally, it would be helpful if you could share the model file so I can replicate the error on my end.
  4 Comments
Abhishek
Abhishek on 23 Apr 2025
Hello @Hitesh,
I tried you code but for Variant B --> It only shows 1 parameter and not both.
Before it was showing Bothh para,eters, no matter what.
Now it shows only one parameter, no matter which variant I select.
Best regards,
Abhishek KUMAR
Hitesh
Hitesh on 5 May 2025
Edited: Hitesh on 5 May 2025
I am getting the TestParameter1 on selecting "VariantA" and TestParameter1 and TestParameter2 on selecting "VariantB". I have attached the simulink model for your reference. I have attached the test_param_file also which will restore the Mask Editor's code that I have written.
Kindly refer to the following code that needs to written in Mask Editor's code tab:
classdef test_param_file
methods(Static)
% Following properties of 'maskInitContext' are available to use:
% - BlockHandle
% - MaskObject
% - MaskWorkspace: Use get/set APIs to work with mask workspace.
function MaskInitialization(maskInitContext)
varObj = get_param(maskInitContext.BlockHandle, 'VariantSelect');
switch varObj
case 'Variant A'
maskObj = Simulink.Mask.get(maskInitContext.BlockHandle);
maskObj.getParameter('TestParam').Visible = 'on';
maskObj.getParameter('TestParam2').Visible = 'off';
case 'Variant B'
maskObj = Simulink.Mask.get(maskInitContext.BlockHandle);
maskObj.getParameter('TestParam').Visible = 'on';
maskObj.getParameter('TestParam2').Visible = 'on';
end
end
% Use the code browser on the left to add the callbacks
end
end

Sign in to comment.

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!