Why do Mask Parameters in models revert back to default when their library block is converted into a reference subsystem?

5 views (last 30 days)
We have a library of cusomised atomic subsystems that we use to build our models. Most of which have mask parameters with set default values. When the library blocks are used in the models, the mask parameters values are often changed from their defaults to fit the specific purpose within that model. However, we are currently trying to convert these atomic subsystems in the library into referenced subsystems following the process shown in your documnetation, namely: "Convert an Existing Subsystem to a Referenced Subsystem" found in https://www.mathworks.com/help/simulink/ug/referenced-subsystem-1.html?searchHighlight=reference%20subsystem&s_tid=srchtitle_support_results_2_reference%20subsystem
After converting to a reference subsystem, we run Simulink.BlockDiagram.refreshBlocks() on the the models which used this converted library block to ensure that this conversion to a reference block pulls and updates through all the levels of our models. This successfully updates all the instances of the converted block to a reference block that references the subsystem .slx file directly (not the library location anymore) which is great! But... it seems this process reverts all the mask parameters of the converted instances of the blocks within the models bag to their defautl mask parameters... which is problematic... is there anyway to ensure that during this process the set mask parameters of the newly converted reference block are kept in each instance within the model and are not reverted backl to their default values.
Thank you.

Answers (1)

Ayush
Ayush on 5 Dec 2023
I understand that you need to intact the mask parameters when converting a library block to a referenced subsystem and using Simulink.BlockDiagram.refreshBlocks(). You may use the following steps to ensure that the set mask parameters of the newly converted reference block are kept in each instance within the model and are not reverted back to their default values:
  • Use Mask initialization and storing the mask parameters:
% Mask Initialization Callback of the referenced subsystem block
function setupMask(block)
% Store mask parameters in the model workspace or data dictionary
set_param(block, 'UserData', get_param(block, 'MaskValues'));
end
  • Restore Mask Parameters: After running Simulink.BlockDiagram.refreshBlocks(), use a post-refresh callback to retrieve the stored mask parameters and reapply them to the updated instances of the referenced subsystem blocks.
% Post-Refresh Callback to restore mask parameters
function restoreMaskParameters(model)
blocks = find_system(model, 'BlockType', 'SubSystem', 'ReferenceBlock', 'myReferencedSubsystem');
for i = 1:length(blocks)
storedMaskValues = get_param(blocks{i}, 'UserData');
if ~isempty(storedMaskValues)
set_param(blocks{i}, 'MaskValues', storedMaskValues);
end
end
end
Documentation for:
  1. Associating User Data with Blocks: https://www.mathworks.com/help/simulink/ug/associating-user-data-with-blocks.html
  2. find_system: https://www.mathworks.com/help/simulink/slref/find_system.html#bu32w05-2
Thank you,
Ayush Jaiswal

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!