MATLAB Answers

How do I programmatically get all variant control labels of a Variant Subsystem when in Label control mode?

4 ビュー (過去 30 日間)
Zachary
Zachary 2020 年 9 月 1 日
編集済み: Uday Pradhan 2020 年 9 月 9 日
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
p.set('TypeOptions', labels)
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?

  0 件のコメント

サインインしてコメントする。

採用された回答

Uday Pradhan
Uday Pradhan 2020 年 9 月 9 日
編集済み: Uday Pradhan 2020 年 9 月 9 日
Hi Zachary,
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.

  0 件のコメント

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by