フィルターのクリア

Programmatically Flip/Rotate Simulink Block

58 ビュー (過去 30 日間)
Timo Dietz
Timo Dietz 2023 年 1 月 24 日
回答済み: Liam Tanner 2024 年 7 月 3 日 8:55
Hi,
I'd like to programmatically rotate/flip a simulink block - arbitrarily. Unfortunately, the 'orientation' property
seems to support specific orientations, only. Thus, no combination of e.g. 'y-mirror' and 90° clockwise rotation
seems to be possible.
Certainly, Simulink supports that via the 'Format' menue but I did not find an accessible block property for this.
Is there a way to access the 'Format/Flip Block' menu of Simulink via Matlab? I did not find a matching property in the slx model, but maybe I overlooked a possibility. Also, I was not able to send key commands to Simulink.
Any suggestions?
Many thanks in advance!

採用された回答

Timo Dietz
Timo Dietz 2023 年 1 月 25 日
編集済み: Timo Dietz 2023 年 1 月 25 日
I finally made it with the help of:
I activate Simulink, select the block to be manipulated and then send kesytrokes for rotating and flipping it.
Not he most elegant approach but it works for me.
Have a nice day!
  3 件のコメント
Philip Hackett
Philip Hackett 2023 年 6 月 19 日
編集済み: Philip Hackett 2023 年 6 月 19 日
In fact it works with an open Simulink window, as in the linked example:
% where the block to be rotated is selected in the GUI
h = actxserver('WScript.Shell');
h.AppActivate('Simulink');
h.SendKeys('^r');
But the block to be rotated must be selected by a mouse click, so it is not a programmatic method that can be used to arrange a model without manual intervention. Setting gcb to the block of interest, as in this answer:
set_param(model, 'CurrentBlock', 'blockName');
does not have the same effect as clicking the block in the GUI.
Timo Dietz
Timo Dietz 2023 年 6 月 19 日
編集済み: Timo Dietz 2023 年 6 月 19 日
What I'm actually doing is the following:
actX = actxserver('WScript.Shell');
newBlock = add_block([libraryBlock], [modelName], 'MakeNameUnique','on');
blockObj = get_param(newBlock, 'Object');
blockObj.Selected = 'on';
Now, the block is selected and its orientation can be changed w/o manual intervention, using ACTX as well as blockObj.Orientation:
blockObj.Orientation = 'up';
actX.AppActivate('Simulink'); % focus on Simulink
actX.SendKeys('^i'); % flip vertically

サインインしてコメントする。

その他の回答 (2 件)

Jean Matthieu
Jean Matthieu 2023 年 1 月 24 日
編集済み: Jean Matthieu 2023 年 1 月 24 日
Hi
set_param(gcb, 'Orientation', 'left')
--> Other keywords are up, right, down
Is that what you're looking for?
  1 件のコメント
Timo Dietz
Timo Dietz 2023 年 1 月 24 日
Thanks for your answer. Unfortunately, these orientation properties do not suffice since they do not cover all possible variations of rotating and mirroring.

サインインしてコメントする。


Liam Tanner
Liam Tanner 2024 年 7 月 3 日 8:55
Hi,
a solution to this problem would be:
newBlock= add_block([libraryBlock], [modelName], 'MakeNameUnique', 'on', 'Position', pos);
set_param(newBlock, 'Orientation', 'down') % Orientation
set_param(newBlock, 'BlockMirror', 'on') % invert
set_param(newBlock, 'BlockRotation', 90) % rotate
I hope it helps ;)

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by