MATLAB: How to determine if two blocks are overlapped in Simulink 6.1 (R14SP1)

automaticallyblocksdiagrammodelmoveoverlappingplacementshiftsimulink

I would like a feature or property for blocks in a Simulink diagram that would let me know if two blocks are overlapping, or something that would ensure that no two blocks are overlapping just like the autorouting feature for signal lines.

Best Answer

Simulink does not check whether blocks overlaps.
To work around this issue, you can obtain the position property of each block in the model and use that information to determine whether two blocks overlap. To obtain the positions of all the blocks in the current model, use the following commands:
bl = find_system(gcs,'type','block');
pos = cell2mat(get_param(bl,'Position'));
This creates an Nx4 matrix, pos, where N is the number of blocks in your model. The columns correspond to the left edge, top edge, right edge, and bottom edge of each of the blocks. You can use this position information to determine if two blocks overlap.
To move the i-th block to a new position use the following command:
set_param(bl{i},'Position',[x0,y0,x1,y1]);