How to find if Simulink block name is visible

17 visualizaciones (últimos 30 días)
Marco Tobia
Marco Tobia el 26 de Jul. de 2023
Respondida: Ananda Raj el 8 de Sept. de 2024
Hello,
I am trying to programmatically find out if the name of a block is shown on the canvas. When the block parameters 'ShowName' and 'HideAutomaticName' are both set to 'on' I can't find a way to know if the name is displayed.
Thank you,
Marco

Respuestas (2)

Manan Jain
Manan Jain el 26 de Jul. de 2023
Hi!
In Simulink, programmatically determining whether the name of a block is shown on the canvas can be a bit tricky, especially when the 'ShowName' and 'HideAutomaticName' parameters are both set to 'on'. When both options are enabled, the block's name might be automatically shown or hidden based on certain conditions, making it less straightforward to determine its visibility.
To check if the name of a block is displayed on the canvas, you can use the MATLAB API for Simulink. Specifically, you can use the get_param function to retrieve the value of the 'ShowName' and 'HideAutomaticName' parameters for the block in question. Then, based on their values, you can infer if the block name is currently displayed.
Here is the snippet of code that you can refer:
function isNameVisible = isBlockNameVisible(blockPath)
% Get the values of 'ShowName' and 'HideAutomaticName'
showName = get_param(blockPath, 'ShowName');
hideAutoName = get_param(blockPath, 'HideAutomaticName');
% Check if the name is set to show
if strcmp(showName, 'on')
isNameVisible = true;
elseif strcmp(showName, 'off')
% Check if the name is set to hide
isNameVisible = false;
else
% The 'ShowName' parameter is set to automatic, check 'HideAutomaticName'
if strcmp(hideAutoName, 'off')
isNameVisible = true;
else
isNameVisible = false;
end
end
end
You can refer to the get_param documentation according to your case. I hope this helps!
  1 comentario
Marco Tobia
Marco Tobia el 27 de Jul. de 2023
Hello there,
Thank you for your answer!
Unfortunately on my Simulink 10.6 (R2022b) I cannot find blocks with 'ShowName' set to anything other than 'on' or 'off' (and as a result the first else of your function is never reached). I have many blocks (e.g., constants) with 'ShowName' = 'on' and 'HideAutomaticName' = 'on' that do not have the name shown on the canvas.
Best regards,
Marco

Iniciar sesión para comentar.


Ananda Raj
Ananda Raj el 8 de Sept. de 2024
Observe the given signal and its derivative on the scope block of MATLAB SIMULINK.

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by