I am facing issue while adding a subsystem in my model using mscript when there is already a subsystem with different name
14 次查看(过去 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
0 个评论
采纳的回答
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
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 Exchange 中查找有关 Subsystems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!