I am facing issue while adding a subsystem in my model using mscript when there is already a subsystem with different name
15 views (last 30 days)
Show older comments
vignesh sainath
on 30 Jan 2024
Commented: vignesh sainath
on 31 Jan 2024
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 Comments
Accepted Answer
Fangjun Jiang
on 30 Jan 2024
Edited: Fangjun Jiang
on 30 Jan 2024
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 Comments
Fangjun Jiang
on 31 Jan 2024
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.
More Answers (0)
See Also
Categories
Find more on Subsystems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!