How do I programmatically get all variant control labels of a Variant Subsystem when in Label control mode?
18 views (last 30 days)
I have a Variant Subsystem. The variant control mode is Label. I'd like to have a popup mask parameter named LabelToActivate to set the active variant choice because my users know how to interact with a mask dialog box and don't know how to use variants (i.e. right-clicking the variant badge or right-clicking the block and navigating to Variant > Label Mode Active Choice).
The code I would put in MaskInitialization is straight-forward. This would run whenever the user applies mask changes.
set_param(gcb, 'LabelModeActiveChoice', LabelToActivate)
However, I don't want to hard-code the TypeOptions of the popup. When the block's LoadFcn callback executes, I want to get all of the labels and set the TypeOptions property of the mask parameter LabelToActivate. I thought there would be a block parameter like VariantControlLabels that I could read. The code in LoadFcn would look something like this...
% Get variant control labels.
labels = get_param(gcb, 'VariantControlLabels');
% Set popup TypeOptions.
m = Simulink.Mask.get(gcb); %my mask
p = m.getParameter('LabelToActivate'); %my popup parameter
Sadly, VariantControlLabels doesn't exist. I can't seem to find any property that stores all of the labels as a cell array of character vectors. Somehow the 'Variant choices' table in the Block Parameters dialog shows the labels in the 2nd column so where are those strings stored?
Uday Pradhan on 9 Sep 2020
Edited: Uday Pradhan on 9 Sep 2020
The list of all the available Variant control labels can be found by selecting the desired Variant subsytem and then executing the command:
out = get_param(gcb,'Variants');
"Variants" is a hidden parameter and is not listed when we search using "ObjectParameters" or "DialogParameters" as arguments. This issue has been forwarded to our developers and it might be resolved (i.e. "Variants" made visible) in a future release. Coming back to your question, you will see that "out" is a struct with fields "Name" and "BlockName". The list of your labels will be stored in the "Name" field. Hope this helps.