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

14 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 21 de Nov. de 2017
Editada: Fangjun Jiang el 21 de Nov. de 2017
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 comentarios
Abhijit Das
Abhijit Das el 24 de Mzo. de 2020
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 el 24 de Mzo. de 2020
Editada: Fangjun Jiang el 24 de Mzo. de 2020
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.

Iniciar sesión para comentar.

Más respuestas (1)

KL
KL el 21 de Nov. de 2017
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');

Categorías

Más información sobre Interactive Model Editing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by