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

15 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Fangjun Jiang
Fangjun Jiang il 30 Gen 2024
Modificato: Fangjun Jiang il 30 Gen 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 Commenti
Fangjun Jiang
Fangjun Jiang il 31 Gen 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Subsystems in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by