Control Linked Block Programmatically
Linked Block Information
Use the libinfo
command to get information about the linked
blocks in the model. libinfo
also provides information about
the parent library blocks of a linked block.
For example, here is a model with linked blocks:
When you execute the libinfo(gcb)
command on this
block:
Block: 'slexMaskVariantExample/VariantSubsystem2' %Linked block Library: 'slexMaskingVariants_libraryblock' %Parent library block ReferenceBlock: 'slexMaskingVariants_libraryblock/VariantSubsystem2' LinkStatus: 'resolved' %Link status
The ReferenceBlock
property gives the path of the library
block to which a block links. You can change this path programmatically by using the
set_param
command. For example:
set_param('slexMaskVariantExample/VariantSubsystem2','ReferenceBlock','slexMaskVariantExample2/VariantSubsystem')
Here, slexMaskVariantExample/VariantSubsystem2
is the original
library block path and slexMaskVariantExample2/VariantSubsystem
is the new library block path.
Note
It is not recommended to change the properties of a referenced block by using
the set_param
command in the mask initialization code or
callback code of the same block. For such modeling patterns, you can use Variant
blocks or use the ReferenceBlock
parameter on the callback
code or the mask initialization code of the parent block of the reference
block.
Lock Linked Blocks
Use the LockLinksToLibrary
command to lock or unlock a linked
block in a library from the command line. When you set the value of
LockLinksToLibrary
to on
, the linked block
links to the library are locked.
set_param('MyLibraryName', 'LockLinksToLibrary', 'on') %Lock links
set_param('MyLibraryName', 'LockLinksToLibrary', 'off') %Unlock links
Link Status
All blocks have a LinkStatus
parameter and a
StaticLinkStatus
parameter to indicate whether the block is a
linked block.
Use get_param(gcb, 'StaticLinkStatus')
to query the link status
without updating the linked blocks. You can use StaticLinkStatus
to query the status of a linked block that is either active or outdated.
Use get_param
to send a query to get the value of the
LinkStatus
.
Get LinkStatus Value | Description |
---|---|
none | Block is not a linked block. |
resolved | Resolved link. |
unresolved | Unresolved link. |
implicit | Block resides in library block and is itself not a link to
a library block. Suppose that A is a link to a subsystem in a
library that contains the Gain block. If you open
A and select the Gain block, |
inactive | Disabled link. |
Use set_param
to set the
LinkStatus
.
Set LinkStatus Value | Description |
---|---|
| Breaks link. Use |
| Breaks links in place without breaking the nested parent
hierarchy of link. For example, |
| Disables link. Use |
| Restores an inactive or disabled link to a library block
and discards any changes made to the local copy of the library
block. For example,
|
| Pushes any changes made to the disabled link to the library
block and re-establishes its link. |
| Restores all disabled links in the hierarchy with their
corresponding library blocks.
|
| Pushes all links with changes in the hierarchy to their
libraries. |
Note
When you use
get_param
to query the link status of a block, the outdated block links also resolve.Using the
StaticLinkStatus
command to query the link status whenget_param
is being used in the callback code of a child block is recommended.StaticLinkStatus
command does not resolve any outdated links.
If you call get_param
on a block inside a library link,
Simulink® resolves the link wherever necessary. Executing
get_param
can involve loading part of the library and
executing callbacks.