Invalid block diagram name supplied

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
madhan ravi on 30 Nov 2023
The block name has to be a valid MATLAB name. Make sure it follow the naming conventions.

10 Comments

and how do I find the block that causes the error? My library is huge and the error does not come with an indication where the fault occurred!
% 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'})
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
I implemented the function as suggested and made it output only invalid names:
I get the following output:
Unfortunately I still get the "invalid block diagram name supplied" error - any further suggestions?
The involved library does not contain any spaces and it is an .slx file. Matlab Version is R2022b.
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)
I exactly used this code and as far as I see the output evil_names contains all entries with Valid ID == 1, therefore the good_names.
The good_and_evil_names and the evil_names output yield equal number of rows - considering the point above I come to the conclusion that I only have valid names, and that is on purpose: after your first comment I went through all the evil_names and corrected them, so I got completely rid of invalid block names. Unfortunately I still get the error when saving the model, BUT:
  • I only get it if I open the model in a new opened R2022b window the first time
  • I can click OK and continue - it won't occur during the subsequent saves.
Itseems strange, maybe a bug report to MathWorks?
I investigated myself and the issue seems to be related to linkage of a library to a data dictionary.
Do the following:
  1. Open a new R2022b instance
  2. Open the Lib_ABC.slx
  3. Unlock the library
  4. Move a block
  5. Save the model
This should lead to the following error:
In 2023b, I didn’t recieve any errors. Following your steps.
Andrea
Andrea on 7 Mar 2024
Edited: Andrea on 7 Mar 2024
I'm having the same issue. It seems to be related with the data dictionary linked to the library.
Version: 2021b

Sign in to comment.

Products

Asked:

on 30 Nov 2023

Edited:

on 7 Mar 2024

Community Treasure Hunt

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

Start Hunting!