Using replace_block with custom simulink library

20 次查看(过去 30 天)
I am trying to create a script that goes through old models looking for outdated versions of custom library blocks and automatically updates them to the newest versions. To do this I am trying to utilize the commands find_system and replace_block. This first to identify which outdated blocks exist in the model, and the second to replace them with the new blocks. However, when attempting to utilize these functions, they report
Invalid NewBlock (<PeakandHold>) passed to
REPLACE_BLOCK.
Try built-in/BLOCKTYPE or a valid block name.
These blocks are all located in a custom library named PME_Library and then organized into folders. When using replace block on just the block name to a built in block type works, but doing it based on block type or when trying to replace the target block with a custom library block results in this error. How do I get these functions to use blocks inside the custom library.

回答(1 个)

tkarg
tkarg 2021-12-9
Maybe it is a bit late for a response but the solution can be helpful for anybody reading.
You need to use path of your custom block -not block type, in the replace_block function. Following code replaces Gain blocks in the model with your custom block.
replace_block(model, 'BlockType', 'Gain', 'your_library/your_block_name');
Another thing, your Simulink library should be loaded into the memory when you are using a block from it (in replace_block or wherever). You can do this by opening it through Simulink, or with the following command in Matlab script:
load_system your_library
These are valid at least for 2021a.

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by