3
votes

Is there's any way to get handles of all selected block using simulink APIs ?

Suppose I select few blocks using mouse, how could I get handles of all selected blocks in form of an array or cells using simulink APIs ?

With gcbh it just gives the handle of recently selected block only.

Basically I want to auto-generate corresponding "From" blocks of all selected "Goto" Blocks and vice-versa.

Matlab Version : 2010b

3

3 Answers

6
votes

This gives you the names of all the selected blocks:

blockNames = find_system('Type', 'Block', 'Selected', 'on')

You should be able to obtain the handle to the blocks by iterating over the cell array and calling get_param(blockName, 'handle'):

for i = 1:length(blockNames)
    blockHandles(i)= get_param(blockNames{i},'handle');
end
2
votes

This doesn't answer the question directly, but if you want to auto-generate "From" blocks, I suggest the following from the File Exchange:

http://www.mathworks.co.uk/matlabcentral/fileexchange/40117-autofromtag

I have used it before and it works very well.

0
votes

If you are using a masked subsystem, ensure you have 'LookUnderMasks' set to 'all':

find_system(gcs, ...
    'SearchDepth'   , 1,...
    'LookUnderMasks', 'all', ...
    'selected'      , 'on');