MATLAB Answers

How to find and replace all broken library links if I renamed my library?

14 views (last 30 days)
I renamed my library, which resulted in many broken links. I want to fix these, but I don't want to do it one-by-one.
How can I find and replace all of these library links programmatically?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 6 Apr 2020
Edited: MathWorks Support Team on 6 Apr 2020
Option 1: Use Forwarding Tables
Using Forwarding Tables would be the easiest way to implement this. For more information can be found in the link below.
*Option 2: Use find_system *
First, a few important details:
- You can use the "find_system" function to find blocks with certain properties.
- You can use the "set_param" function to programmatically change the properties of a block.
- Blocks linked from libraries have a parameter called "ReferenceBlock" which indicates the library and block that this block is linked to.
- When a library link is broken, the parameter "ReferenceBlock" is an empty array, and cannot be changed using "set_param".
So, using the above information, we can loop through the broken blocks using "find_system", and set their library links using "set_param" on the "ReferenceBlock" parameter.
The key is, to set the "ReferenceBlock" parameter, both the old and the new library names must be valid. However, in your case, the old library link is invalid. Here is the procedure I propose to get around this:
1. Copy your new library, and rename this copy to have the same name as the old library. This will temporarily resolve all of the broken library links.
2. Write a script that uses the "find_system" function to find all blocks for which you'd like to change library links.
3. Use "set_param" on each block to change the "ReferenceBlock" parameter to match the name and block of the new library.
4. Delete the copy of the library (the one with the old name).

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Products


Release

R2017b