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

10 visualizzazioni (ultimi 30 giorni)
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.

Risposte (2)

Abhisek Pradhan
Abhisek Pradhan il 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 il 4 Nov 2021
Modificato: Alexandre de Langlade il 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')
end
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 '/']);
sfclose(sf_blk);
else
close_system(blk);
end
end
end
% Finally, set Zoom factor of top level
set_param(Blocks_List{1}, 'ZoomFactor', 'FitSystem')
clear Blocks_List block blk;
end
  1 Commento
Adam Clark
Adam Clark il 9 Mag 2022
This is great -- Thank you! I've been wanting to do this for years, but finally got around to researching the commands.

Accedi per commentare.

Categorie

Scopri di più su Modeling in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by