Error modifying mask parameter name in MaskCallback

8 views (last 30 days)
I have a mask for a top-level library subsystem (with 'allow library block to modify its contents' checked), and this mask has two types of mask parameters: parameters that do not go away and parameters that are created/destroyed based on the user input of the first type of parameter (i.e., exParam1 declares number of additional parameters, and exParam2:exParamn are created and destroyed). Here, toggling visibility will not work because I have no ceiling, and the actual system is more complex than described.
Removing parameters by their 'Name' property works fine, but the trouble comes with adding parameters; Simulink does not like 'modifying' a mask parameter's name from the context of a mask callback (even if all I need to do is initialize to one name), and the MathWorks documentation even discourages using the initialization code to create this dynamic mask dialog box functionality in Mask Initialization Best Practices, declaring that mask callbacks are exactly for this purpose. Running the same functions in the command line context works fine, however. I have attempted to run functions in the base workspace from the callback to circumvent this problem, but that does not escape the MaskCallback context.
I am running MATLAB/Simulink R2015b, attached is the error produced by Simulink (without error code unfortunately), and below is an example Simulink.Mask.addParameter() command for running in a callback that creates the error at the name assignment:
maskHandle = Simulink.Mask.get(gcb);
numParams = str2double(get_param(gcb,'numParams'));
for i=1:numParams
maskHandle.addParameter(...
'Name',blockNameArray(i),... // This is the error for MaskCallback
'Type','edit',...
'Prompt',blockPromptArray(i),...
'Value','1',...
'Container',tabName);
end
Is this intended functionality in Simulink? Is there some way around this issue that does not involve scrapping the masking approach altogether?
  1 Comment
Bruno Correia Gracio
Bruno Correia Gracio on 6 Sep 2019
This seems to be an old question but did anyone found a solution?
I'm trying to do the same but I'm having issues to addParameters or removeParameters from a mask dynamically. I'm trying to achive something similar to what the Simulink Selector blocks where a parameter in the mask will control the number of the table entries that is also in the mask. However, when I set the addParam/removeParam code in the mask init, it says it is not possible to change the number of parameters. Therefore, I added the code to the MaskCallback of the paramter that is controlling the number of table rows. However, in this case I get the error: "(...) Changing mask parameter name as part of MaskCallbacks is not allowed." Does anyone know where the code should be added in order to get a mask that changes dinamically, similar to the Selector block?
Many thanks

Sign in to comment.

Answers (0)

Categories

Find more on Author Block Masks in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!