Skip to content

Instantly share code, notes, and snippets.

@luisdamed
Created April 7, 2023 13:31
Show Gist options
  • Save luisdamed/c500026075fafda70f43f9c3d733fb90 to your computer and use it in GitHub Desktop.
Save luisdamed/c500026075fafda70f43f9c3d733fb90 to your computer and use it in GitHub Desktop.
Batch-create matching Simulink From blocks based on the current selection of Goto blocks. Read the article I wrote about this: https://www.makerluis.com/3-keyboard-macros-to-speed-up-your-simulink-workflow/
subsystem = gcs;
goto_objects = Simulink.findBlocksOfType(selection, 'Goto', 'Selected', 'on');
for i_block = 1:numel(goto_objects)
tag = get_param(goto_objects(i_block), 'Gototag');
origin_position = get_param(goto_objects(i_block), 'Position');
dest_block = [subsystem '/Goto'];
dest_position = origin_position + [200 0 200 0];
handle = add_block('built-in/from', dest_block, 'MakeNameUnique','on');
set_param(handle, 'Gototag', tag, 'Position', dest_position);
open_system(subsystem );
end
% save as batchgoto.m
% add to MATLAB Path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment