How to get the exact file pathname for a linked library

12 visualizaciones (últimos 30 días)
Prabhakar Vallury
Prabhakar Vallury el 28 de Jun. de 2023
Editada: Prabhakar Vallury el 7 de Jul. de 2023
Matlab version: 2019b
Hello,
I have a Simulink 'system' model that contains several linked libraries (.slx files) from various folders. I would like to modify signal-names/data in the system model and propagate those back to the linked library files. For this, I'm using the commands
li = libinfo(bdroot);
for i = 1:length(li)
if ~strcmp(li(i).Library, 'simulink') % Ignore libraries named simulink
lib1 = sprintf("%s", string(li(i).Block)); % Get the Block name
each_lib = split(lib1, '/');
for j = length(each_lib):-1:1
this_lib = strjoin(each_lib(1:j), '/'); % Iterate to create a list of all possibilities
try
set_param(this_lib, 'LinkStatus', 'propagate') % Push the system changes to the library.
save_system(this_lib); % Save the library & close it
close_system (this_lib);
end
end
end
end
[This forced method is not bad, because the code skips over any library strings that cannot or do not need to be modified.]
This opens the corresponding linked library in a different window and pushes the changes, all good. However, the save_system gives an error indicating the library .slx file is being shadowed because another file with the same name exists in a different folder. How can I get the exact path-name for the .slx file corresponding to the linked library above so I can save the correct one? Or is there a totally better/faster way of achieving this goal?
Thanks in advance.
Joe

Respuestas (1)

Fangjun Jiang
Fangjun Jiang el 28 de Jun. de 2023
save_system() has options to skip prompt, ignore warning and force save.
If there are multiple files with the same name as the Simulink library file, something must be done before opening the model to make sure the library file is the correct one. Otherwise, once "propagagted", it is too late.
Once getting the libinfo(), you can use the which('libname','-all') to see all the matching files. Once confirmed that the library is correct, force save with confidence.
  4 comentarios
Prabhakar Vallury
Prabhakar Vallury el 7 de Jul. de 2023
Editada: Prabhakar Vallury el 7 de Jul. de 2023
Figured this out. Here is the code to find all user libraries that need to be updated/propagated with changes from the system model. Matlab automatically knows the correct user-library, so no need to find the path.
li = libinfo(bdroot);
saved_libs = []
for i = 1:length(li)
if strcmp(li(i).LinkStatus, 'inactive')
sprintf("Pushing changes to user library %s", li(i).Library)
try
open_system(li(i).Library)
lock_status = get_param(li(i).Library, 'Lock');
if strcmp(lock_status, 'on')
set_param (li(i).Library, 'Lock', 'off');
end
set_param(li(i).Block, 'LinkStatus', 'propagate')
save_system(li(i).Library);
close_system(li(i).Library);
saved_libs = [saved_libs ' ' li(i).Library];
catch ME
sprintf("ERROR saving %s: %s %s", li(i).Library, ME.message, extractAfter(ME.stack(1).name))
ontinue
end
end
end
sprintf("Following user libraries have been saved: %s", string (saved_libs))
Prabhakar Vallury
Prabhakar Vallury el 7 de Jul. de 2023
Movida: Fangjun Jiang el 7 de Jul. de 2023
This issue can be closed. Thanks!

Iniciar sesión para comentar.

Categorías

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

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by