MATLAB: Promote parameter and add it to tab programatically

mask programaticallyparametersimulinktab

Hello, I'm trying to create a mask of a 'parent' block in which the masks of 'child' blocks would appear as tabs (with all parameters promoted to the parent mask). First I create a tab:
parentMask = Simulink.Mask.get(parentBlock);
tabs = parentMask.addDialogControl('tabcontainer','tabCont');
tab = tabs.addDialogControl('tab','tab');
Now I'm trying to promote parameter from child and add it to the tab:
childMask = Simulink.Mask.get(childBlock);
param = childMask.Parameters(1); %for simplicity
and now I'm stuck in adding the parameter to the tab
props = {'Type','promote',...
'TypeOptions',{[get_param(childBlock,'Name'),'/',param.Name],... %not documented?, guessed by reverse-engineering
'Name',param.Name,...
'Prompt',param.Prompt,...
'TabName',tab.Name};
parentMask.addParameter(props{:});
but I get: Warning: 'TabName' cannot be set for 'system/parentBlock' as it will be removed in a future release. Use tab dialog controls to add parameters to tabs
I could not figure out a way how to add parameters to the tab as suggested by the hint. It is not documented (yet?).
1) How do I add any parameter to tab programmatically?
2) Or better, in the object world, is there a chance to promote a parameter just by passing its handle, for example by:
tab.addParameter('Type','promote',param)
There are also some bugs I've found on the way:
  • example from https://nl.mathworks.com/help/simulink/slref/simulink.maskparameter.set.html does not work ('TabName' property)
  • properties in https://nl.mathworks.com/help/simulink/slref/simulink.mask.adddialogcontrol.html contain a strange 'Filepath' property, probably just instead of 'TabName'
  • there is no way how to discover/remove dialog controls without knowing their name. Magically, however, https://nl.mathworks.com/help/simulink/ug/control-masks-programmatically.html contains undocumented method getDialogControls, which can serve the purpose. Or by another undocumented way by invoking parentMask.DialogControls property.
The object-oriented way to mask creation is a big step towards user-friendliness when it comes to mask creation. I hope resolving these issues will help to move the cause further.
Thank you.

Best Answer

The 2017 documentation is incomplete and fail to provide the actual way of doing it.
The 2014b documentation however is complete. Here is what is missing:
6 - Move the mask parameters you created previously to the first tab.
opt1 = maskobj.getDialogControl('option1');
opt2 = maskobj.getDialogControl('option2');
opt1.moveTo(tab1);
opt2.moveTo(tab1);
I am also giving you an MWE with an edit field and a popup:
block = 'Untitled1/Atomic Subsystem';
wMask = Simulink.Mask.get(block);
if ~isempty(wMask)
wMask.delete();
end
wMask = Simulink.Mask.create(block);
wMask.addDialogControl('tabcontainer','tabContainer');
wTabContainer = wMask.getDialogControl('tabContainer');
wTab1 = wTabContainer.addDialogControl('tab', 'Tab1');
wTab2 = wTabContainer.addDialogControl('tab', 'Tab2');
wTab1.Prompt = 'Programatically added tab1';
wTab2.Prompt = 'Programatically added tab2';
wTextOnFirst = wTab1.addDialogControl('text', 'textOnFirst');
wTextOnFirst.Prompt = 'Some text on the first tab';
wTextOnSecond = wTab2.addDialogControl('text', 'textOnSecond');
wTextOnSecond.Prompt = 'Some text on the first tab';
wField = wMask.addParameter('Name', 'TextField' ...
, 'Type', 'edit'...
, 'Prompt', 'Programatically added text field'...
, 'Value', 'Toto'...
, 'Evaluate', 'on'...
, 'Tunable', 'off'...
, 'Enabled', 'on'...
, 'Visible', 'on'...
, 'Callback', 'disp( get_param(gcb, ''TextField''))');
wPopup = wMask.addParameter('Name', 'PopupField' ...
, 'Type', 'popup'...
, 'Prompt', 'Programatically added popup field'...
, 'TypeOptions', {'Value1', 'Value2', 'Value3'}...
, 'Evaluate', 'on'...
, 'Tunable', 'off'...
, 'Enabled', 'on'...
, 'Visible', 'on'...
, 'Callback', 'disp( get_param(gcb, ''PopupField''))');
wFieldDialog = wMask.getDialogControl('TextField');
wPopupDialog = wMask.getDialogControl('PopupField');
wFieldDialog.moveTo(wTab1);
wPopupDialog.moveTo(wTab2);