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

조회 수: 7 (최근 30일)
Abhishek
Abhishek 2025년 4월 8일
편집: Hitesh 2025년 5월 5일
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.

답변 (1개)

Hitesh
Hitesh 2025년 4월 10일
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
Abhishek
Abhishek 2025년 4월 23일
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 2025년 5월 5일
편집: Hitesh 2025년 5월 5일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Create Block Masks에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by