フィルターのクリア

I am facing issue while adding a subsystem in my model using mscript when there is already a subsystem with different name

6 ビュー (過去 30 日間)
Hi
I am facing the below error while adding a subsystem in my model using mscript when there is already a subsystem with different name
My Code to add a subsystem to model:
bh = Simulink.findBlocks('Script_Test');
Simulink.BlockDiagram.createSubsystem(bh,'Name','ss2');
Error Window details:
Error using createSubsystemImpl
Blocks and annotations must belong to the same parent to create a new subsystem
Error in slprivate
Error in Simulink.BlockDiagram.createSubsystem
Error in SW_Script (line 164)
Simulink.BlockDiagram.createSubsystem(bh,'Name','ss2'); - Show complete stack trace
Displaying stack trace:
Error using createSubsystemImpl
• In createSubsystemImpl
• In slprivate
• In Simulink.BlockDiagram.createSubsystem
• In SW_Script (line 164)while adding a subsystem in my model using mscript when there is already a subsystem with different name

採用された回答

Fangjun Jiang
Fangjun Jiang 2024 年 1 月 30 日
編集済み: Fangjun Jiang 2024 年 1 月 30 日
The way you run bh = Simulink.findBlocks('Script_Test'), the returned blocks are not in the same level, thus the error.
Most likely, you mean to do this:
f = Simulink.FindOptions('SearchDepth',1)
bh = Simulink.findBlocks('Script_Test',f);
Simulink.BlockDiagram.createSubsystem(bh,'Name','ss2');
  3 件のコメント
Fangjun Jiang
Fangjun Jiang 2024 年 1 月 31 日
Read the help doc of Simulink.findBlocks and Simulink.BlockDiagram.createSubsystem, you should be able to figure it out.
Likely, if you change one line to bh = Simulink.findBlocks('Script_Test\ExistingSysName',f), it will copy all the blocks inside "ExistingSysName" block.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSchedule Model Components についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by