This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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:

Masking variant 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, it is you can use Variant blocks (Masking variant blocks) or use the referenceblock command on the callback code or the mask intialization 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 either active or outdated.

Use get_param to send a query to get the value of the LinkStatus.

Get LinkStatus ValueDescription
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, get_param(gcb, 'LinkStatus') returns implicit.

inactive

Disabled link.

Use set_param to set the LinkStatus.

Set LinkStatus ValueDescription

none

Breaks link. Use none to break a link, for example, set_param(gcb, 'LinkStatus', 'none').

breakWithoutHierarchy

Breaks links in place without breaking the nested parent hierarchy of link. For example, set_param(gcb, 'LinkStatus', 'breakWithoutHierarchy').

inactive

Disables link. Use inactive to disable a link, for example, set_param(gcb, 'LinkStatus', 'inactive').

restore

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, set_param(gcb, 'LinkStatus', 'restore') replaces the selected block with a link to a library block of the same type. It discards any changes in the local copy of the library block.

restore is equivalent to Restore Individual in the Links Tool.

propagate

Pushes any changes made to the disabled link to the library block and re-establishes its link. propagate is equivalent to Push Individual in the Links Tool.

restoreHierarchy

Restores all disabled links in the hierarchy with their corresponding library blocks. restoreHierarchy is equivalent to Restore in hierarchy mode in the Links Tool.

propagateHierarchy

Pushes all links with changes in the hierarchy to their libraries. propagateHierarchy is equivalent to Push in the Hierarchy mode of the Links Tool. See Restore Disabled or Parameterized Links.

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 when get_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.

See Also

|