Effacer les filtres
Effacer les filtres

How can I access to the tabs in Simulink editor by script?

24 vues (au cours des 30 derniers jours)
Ivo Kahl
Ivo Kahl le 28 Juil 2020
Commenté : Adam Clark le 9 Mai 2022
Usually it's possibe to open subsystems by "Open in new tab" by mouse action.
If theese tabs were not closed before saving the model it reopenes in same (all tabs open) way.
I want to create a script (e.g. for usage in pre-save callback), that closes all tabs except the first one.
The necessary command to access theese tabs was not yet found by me.
I'm using ML 2017B with matching Simulink-version.

Réponses (2)

Abhisek Pradhan
Abhisek Pradhan le 13 Nov 2020
I am not sure if this can be done through any of the MATLAB functions but it can be done using some external automation tools, which takes control of MATLAB and can perform various GUI actions.

Alexandre de Langlade
Alexandre de Langlade le 4 Nov 2021
Modifié(e) : Alexandre de Langlade le 4 Nov 2021
I have just made a script that does exactly that !
Enjoy !
function preSave(system_name)
% preSave PreSaveFcn callback
Blocks_List = find_system(system_name);
% Since we close everything, need to open at least toplevel of
% specified system in case it was not open already
open_system(Blocks_List(1), "tab");
% Index starts at 2 to not close toplevel
for block = Blocks_List(2:end)'
blk = block{:};
% Bonus : Set Zoom factor to fit the window
if strcmp(get_param(blk, 'BlockType'), 'SubSystem')
set_param(blk, 'ZoomFactor', 'FitSystem')
if contains(blk,"/")
if is_stateflow(blk) % Function that checks whether system is a stateflow : look it up if you want
% sfclose considers chart names without toplevel
% name in path, so we remove it
sf_blk = extractAfter(blk,[system_name '/']);
% Finally, set Zoom factor of top level
set_param(Blocks_List{1}, 'ZoomFactor', 'FitSystem')
clear Blocks_List block blk;
  1 commentaire
Adam Clark
Adam Clark le 9 Mai 2022
This is great -- Thank you! I've been wanting to do this for years, but finally got around to researching the commands.

Connectez-vous pour commenter.


En savoir plus sur Modeling dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by