How can I change the color of all similar blocks in a complex simulink system programmatically?

11 ビュー (過去 30 日間)
I have multi level simulink system with masked subsystems and libraries. The previous owners have the coloring jumbled and I want to write a script to find all blocks of the same type and change the color of those blocks.
Think of this as enforcing styling guidelines.

採用された回答

Fangjun Jiang
Fangjun Jiang 2017 年 11 月 21 日
編集済み: Fangjun Jiang 2017 年 11 月 21 日
Something like this but modifying blocks inside library links is tricky. I would suggest you modify the library directly. Open the library model, unlock it and run the script against the library model file. Then all the library links in your model should be updated automatically.
%%load the example f14 model
f14;
Model='f14';
GainBlks=find_system(Model,'FindAll','On','LookUnderMasks', 'All','BlockType','Gain');
set(GainBlks,'BackgroundColor','red');
  2 件のコメント
Abhijit Das
Abhijit Das 2020 年 3 月 24 日
Thanks. Just wanted to make sure if I understand the concept right. So, if I change the color of a custom library block, it should affect the same block color in the model, right? If that is the case, then I am not seeing the same with my model and library model. When I changed the background color of my library blocks, it did not change the color in the model. I checked the links and everything looks normal. Let me know if that is expected. Thank you!
Fangjun Jiang
Fangjun Jiang 2020 年 3 月 24 日
編集済み: Fangjun Jiang 2020 年 3 月 24 日
You have a block in your library. If you change the color of the block itself and drag an instance to your model, the instance will have the new color. However, the previously existing instances in your model won't change to the new color. I assume that is because the color (probably some other properties such as font and position) is not a property important to the library element. In fact, you can change the color of the instances in your model, it is allowed and it won't require to update to the library. Same thing is true for size. We change the size of the block in the model all the time.
If the block in the library is a subsystem and you changed the color of one of the blocks inside the subsystem, all the instances (old or new) in your model will have the new color for that internal block.

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

その他の回答 (1 件)

KL
KL 2017 年 11 月 21 日
use findblocks to get all blocks of your model,
and then apply if else or your logic to separate your blocks and use setparam and BackgroundColor property like,
set_param(gcb,'BackgroundColor','red');

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by