Restoring library links
1 view (last 30 days)
Show older comments
Hello All, I have a instantiated library block in my model, which link is set to inactive. I have removed some parameters from its library block. Also, the instantiated block has some parameters which values are differ from the library block and i do not like to change them. How can I apply library block changes in instance without loosing local changes. It can be done via gui(Link Options->Restore Link), but I need to do this programmatically(via set_param command)
Any help is appreciated. Thanks
0 Comments
Accepted Answer
Fangjun Jiang
on 3 Dec 2011
You need to be very careful about this type of operation. Depending on what do you mean by "parameters", I am not sure if you can merge the changes made both on the library blocks and the instantiated blocks in the model. But if you say that the GUI operation via Link OPtions -> Restore Link can achieve what you want, then you can do it in script. Try an example first to make sure it works before you apply to the whole model.
LibraryBlocks=find_system(MyModel,'FollowLinks','On','LookUnderMasks','All',...
'LinkStatus','inactive');
% restore libraries, from inside to outside because library might be
% nested
for i=length(LibraryBlocks):-1:1
try
Lib_Model=get_param(LibraryBlocks{i},'AncestorBlock');
Lib_Model=regexprep(Lib_Model,'/.+','');
open_system(Lib_Model);
set_param(LibraryBlocks{i},'LinkStatus','restore');
fprintf(1, 'Info: Restore block ''%s'' from library file "%s".\n\n',LibraryBlocks{i},Lib_Model);
catch %#ok<*CTCH>
fprintf(2, 'ERROR: Can not restore block ''%s'' to library file "%s".\n\n',LibraryBlocks{i},Lib_Model);
end
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Simulink Environment Customization 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!