Invalid block diagram name supplied
Show older comments
Get an error when opening a library changing something and saving it - unfortunately the error is only occurring from time to time so it is almost impossible to troubleshoot because I cannot reproduce it reliably. Any guidance on how to find the root cause of the issue?

Answers (1)
madhan ravi
on 30 Nov 2023
0 votes
The block name has to be a valid MATLAB name. Make sure it follow the naming conventions.
10 Comments
Silvan Pluess
on 1 Dec 2023
madhan ravi
on 1 Dec 2023
% Open or load the Simulink model
model_name = 'untitled1'; % Replace with your Simulink model name
open_system(model_name);
% Get all blocks in the model
blocks = find_system(model_name, 'Type', 'Block');
% Get the names of all blocks
block_names = get_param(blocks, 'Name')
% Get the indices of blocks with valid names
val_idx = cellfun(@(x) isvarname(x), block_names, 'un', 1)
evil_names = cell2table([blocks, block_names, num2cell(val_idx)], 'VariableNames', {'Block Path', 'Block Name', 'Valid ID'})
madhan ravi
on 1 Dec 2023
Edited: madhan ravi
on 1 Dec 2023
Note: Make sure the name of the library(valid name) you are trying to save does not have space at the beginning or at the end of the library name. That is why it’s always a good idea to run Model Advisor checks.
Result:
evil_names =
9x3 table
Block Path Block Name Valid ID
_________________________________________ ______________ ________
{'untitled1/Subsystem=' } {'Subsystem='} false
{'untitled1/Subsystem=/In1' } {'In1' } true
{'untitled1/Subsystem=/(' } {'(' } false
{'untitled1/Subsystem=/(/In1' } {'In1' } true
{'untitled1/Subsystem=/(/Subsystem' } {'Subsystem' } true
{'untitled1/Subsystem=/(/Subsystem/In1' } {'In1' } true
{'untitled1/Subsystem=/(/Subsystem/Out1'} {'Out1' } true
{'untitled1/Subsystem=/(/Out1' } {'Out1' } true
{'untitled1/Subsystem=/Out1' } {'Out1' } true
Silvan Pluess
on 4 Dec 2023
madhan ravi
on 4 Dec 2023
Yes, because you didn't try my exact code.
% Open or load the Simulink model
model_name = 'untitled1'; % Replace with your Simulink model name
open_system(model_name);
% Get all blocks in the model
blocks = find_system(model_name, 'Type', 'Block');
% Get the names of all blocks
block_names = get_param(blocks, 'Name')
% Get the indices of blocks with valid names
val_idx = cellfun(@(x) isvarname(x), block_names, 'un', 1)
good_and_evil_names = cell2table([blocks, block_names, num2cell(val_idx)], 'VariableNames', {'Block Path', 'Block Name', 'Valid ID'})
evil_names = good_and_evil_names(good_and_evil_names{:, 3}, 1 : 2)
Silvan Pluess
on 5 Dec 2023
madhan ravi
on 5 Dec 2023
Itseems strange, maybe a bug report to MathWorks?
Silvan Pluess
on 6 Dec 2023
Moved: madhan ravi
on 6 Dec 2023
madhan ravi
on 6 Dec 2023
In 2023b, I didn’t recieve any errors. Following your steps.
Categories
Find more on Subsystems 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!

