Simulink.B​lockDiagra​m.arrangeS​ystem without resizing blocks

2 Ansichten (letzte 30 Tage)
There exist a way to rearrange the simulink scheme without resizing the blocks?
More details: I have created a custom library with my blocks and I'm using them to build a scheme through matlab code. For this reason I need to use the function Simulink.BlockDiagram.arrangeSystem to rearrange the scheme, but this also resize all the blocks, while I need them to remain with the shape and size I set in the original library blocks icons (In particular I have a small rectangle that is reshaped to a bigger square).
So there is a way to perform arrangeSystem without resizing or fix the size/scale of my diagram blocks before running that function?
Thank you

Akzeptierte Antwort

Alessandro Nocentini
Alessandro Nocentini am 13 Okt. 2023
Bearbeitet: Alessandro Nocentini am 13 Okt. 2023
If this could be useful for someone else, I found a solution to my problem by saving the components dimentions, using get_param function.
In particular Position(3)-Position(1) for the width and Position(4)-Position(2) for the height, then arrange the scheme with arrangeSystem function and finally resize the blocks to the original dimensions and keeping them centered to the new position.
It's not good but it works for now.
If anyone knows a better way to do this let me know
% Get a list of all the blocks in the model
blocks = find_system('myModel', 'SearchDepth', 1, 'Type', 'Block');
% Get dimension for each block (here the variables Width and Height overwrite at every loop iteration)
for i = 1 : length(blocks)
currentBlock = blocks{i};
BlockPosition = get_param(currentBlock, 'Position');
blockWidth = BlockPosition(3)-BlockPosition(1);
blockHeight = BlockPosition(4)-BlockPosition(1);
end
Simulink.BlockDiagram.arrangeSystem('myModel')
% Resize the blocks keeping them centered with the new position
newBlockPosition = get_param(currentBlock, 'Position');
newBlockPosition(1) = newBlockPosition(1) + (newBlockPosition(3)-newBlockPosition(1)-blockWidth)/2;
newBlockPosition(2) = newBlockPosition(2) + (newBlockPosition(4)-newBlockPosition(2)-blockHeight)/2;
newBlockPosition(3) = newBlockPosition(1) + blockeWidth;
newBlockPosition(4) = newBlockPosition(2) + blockHeight;
set_param(currentBlock, 'Position', newBlockPosition);
  1 Kommentar
Chuyen
Chuyen am 26 Okt. 2023
Hello Alessandro, I wondered that how your blocks were changed when triggering Simulink.BlockDiagram.arrangeSystem command because it did not occur from my side. Could you show me your example?
Besides, I also applied this command to my model but I got an issue that my library block included a function call block, from that it made the position arrangement between input and that function call block mess up.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Model Editing finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by