MATLAB/Simulink: Update a Specific Linked Library Block Instead of All Instances

I have created a CounterDesign subsystem as a parent library block and use it as a linked library block in multiple locations within my Simulink model:
  • Main/Subsystem1/sub1/CounterDesign
  • Main/Subsystem1/sub2/CounterDesign
  • Main/Subsystem1/sub3/CounterDesign
  • Main/Subsystem1/sub4/CounterDesign
I wrote an automation script to update the comment of the Switch1 block inside only the following instance:
Main/Subsystem1/sub1/CounterDesign/Switch1
Specifically, I want to set the comment to "This can't be covered".
However, the script updates the Switch1 block in all linked instances:
  • Main/Subsystem1/sub1/CounterDesign/Switch1
  • Main/Subsystem1/sub2/CounterDesign/Switch1
  • Main/Subsystem1/sub3/CounterDesign/Switch1
  • Main/Subsystem1/sub4/CounterDesign/Switch1
I do not want to modify the parent library or affect the other linked instances. I only want to update the linked block at the specific model path.
Is there a way to modify the comment for only a specific linked library block instance without updating the parent library or the other linked instances?
blk_path = Main/Subsystem1/ sub1/CouterDesign
blockPath = Main/Subsystem1/ sub1/CouterDesign/Switch1
set_param(blk_path,'LinkStatus', 'inactive');
try
setmt(blockPath,'comment.placement',2);
setmt(blockPath,'comment.text','');
set_param(blk_path,'LinkStatus', 'propagate');
libInfo = libinfo(blockPath);
save_system(libInfo.Library);
catch x
disp(x.message);

2 Kommentare

Hi Murugan,
What is the "setmt" command?
Why is the code setting the LinkStatus to 'propagate' and then saving the library?
% setmt is Target link m file.
% step 1 - Disbale Link the "CounterDesign" via inactive.
% step 2 - update the switch block
% step 3 - push my changes via propagate
% step 4 - Save the CounterDesign.
after updating the swithc block I am pushing my chages via propagate.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

"Is there a way to modify the comment for only a specific linked library block instance without updating the parent library or the other linked instances?"
Yes.
  1. In your code, you could try not to run the line set_param(blk_path,'LinkStatus', 'inactive'). It may cause a "parameterized link".
  2. In your code, you could not to run the line set_param(blk_path,'LinkStatus', 'propagate'). It will cause a disabled link. But that is a reality that you have to accept. You have an instance that is different than the library and the other three instance.
  3. Your code to change the format of the comment might be just an example. If you want to make different instances to have different parameter values, you should create a masked parameter for the library block.
Search "Parameterized Links and Self-Modifiable Linked Subsystems" in the document should lead you there.

8 Kommentare

I want to update the code comment part like below
Try this.
  1. Not to run set_param(blk_path,'LinkStatus', 'inactive')
  2. Run setmt(blockPath,'comment.text','')
  3. Not to run set_param(blk_path,'LinkStatus', 'propagate')
It might be able to run without error. It will leave a parameterized link. That is the best you can do based on your use case.
Without running this line "set_param(blk_path,'LinkStatus', 'inactive')" how can we update the library's block. Because the library blocks are linked.
I know this and I have just verified it in Simulink. You could try it in TargetLink.
Setting the "Gain" value different than its library block caused a parametrized link.
Setting the "Description" text different than its library block didn't cause a parameterized link. This is good for you but could be an issue in general, because there is no clear and easy way to tell that it is different than its library block.
Related properties:
set_param(Blockpath,'AttributesFormatString', '%<Description>')
set_param(Blockpath,'Description','This is a totally different description.')
when i open the the library subsystem,we can see down. this is locked and we can't edit this.
if I run "set_param(blk_path,'LinkStatus', 'inactive')", then only i can see the ready and we can edit this one.
Try run setmt() directly in command line, not to edit it through GUI.
When I run setmt() directly, I get an error because this library block has been locked.
This seems to be constrained by dSPACE.
I've tried this. You could use set_param() to modify the 'MaskValues' property to make it work.

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

am 6 Aug. 2026

Kommentiert:

am 13 Aug. 2026

Community Treasure Hunt

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

Start Hunting!

Translated by