Change all block names Simulinkin a List
6 views (last 30 days)
Show older comments
Hi,
i have a model from another company to integrate in our own and we want to translate the model first. I dont speak the language and the translator does not know how to use simulink.
Is there a way to get all the names (Block names, Port lables) in a list form? Basically i would need a list of Blockhandle, Old Name. Then the translator can assign new names to the block handles and i can write them back. I know i can use the find_system to get the handle of a known block, but how to get the handle on any block and how to iterate through all?
0 Comments
Answers (1)
Saffan
on 1 Jul 2023
I understand that you want to get a list of all the block names and port labels in the Simulink model as well as their handles. It can be achieved using “find_system” and “get_param” function as shown in the following code snippet:
% Open the model
model = 'BlockNames';
open_system(model);
% Get all block handles and names
blocks = find_system(model, 'LookUnderMasks', 'all', 'FollowLinks', 'on');
blockNames = get_param(blocks, 'Name');
You can iterate over the handles and replace the names with the translated names in the following way:
for i=1:size(blocks)
% get the new block name from the newBlockNames array which contains the translated block names.
translatedName = newBlockNames{i};
% update the block name using set_param function
set_param(blocks{i},'Name',translatedName);
end
The “set_param” function is used to modify parameters of Simulink blocks or models programmatically. Refer to these links for more information:
0 Comments
See Also
Categories
Find more on Programmatic Model Editing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!