At a high level, you can accomplish this using the 'find_system' and 'close_system' commands. The specifics of how you call these depends on what you would like to close, but your workflow will likely take the following form:
- Create a new MATLAB script so that you can easily call your 'close everything' routine.
- Within the script, use 'find_system' to get references to all Simulink blocks you would like to close. For example, to get all scope blocks, you can call it like this:
blocksToClose = find_system(bdroot, 'BlockType', 'Scope')
You may need to perform multiple 'find_system' calls to obtain handles to all of the blocks you would like to close. - Once you have handles to all of the blocks you would like to close, you can call 'close_system' to close their dialog boxes:
close_system(blocksToClose)
- Run the script every time you would like to execute this behavior.
Depending on how many types of blocks you would like to close, it may instead be easier to find all of the blocks you do not want to close, and then take the complement. For example, let's say that you would like to close all Simulink block windows besides any systems/subsystems you have open. In this example, it would be more direct to:
- Create a MATLAB script.
- Call the below code to find all blocks in your model:
blocks = find_system(bdroot)
- Call the below code to find all subsystems in your model:
subsystems = find_system(bdroot, 'BlockType', 'Subsystem')
- Remove all blocks in the result from 3 from the result from 2. Then, call 'close_system' on this result. E.g.,
toClose = blocks(~ismember(blocks, subsystems))
toClose[1] = []
close_system(toClose)
Thus, we can close everything except for our main system and subsystems.
To learn more about these MATLAB functions, please see the below documentation pages:
- find_system
- close_system
Specifically, I would like to direct your attention to the 'LookUnderMasks' flag for 'find_system', which might be needed if you would like to close the windows of blocks that are hidden under masked subsystems.