How can I access to the tabs in Simulink editor by script?
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (2)
Abhisek Pradhan
el 13 de Nov. de 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.
0 comentarios
Alexandre de Langlade
el 4 de Nov. de 2021
Editada: Alexandre de Langlade
el 4 de Nov. de 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 comentario
Adam Clark
el 9 de Mayo de 2022
This is great -- Thank you! I've been wanting to do this for years, but finally got around to researching the commands.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!