R2023A Behaviour change in Simulink.findBlocks and Simulink.BlockDiagram.createSubSystem
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I'm working on an application that needs to split simulink models into subsystems. With R2023A our code stopped working, giving error:
Blocks and annotations must belong to the same parent to create a new subsystem.
We eventually figured out that this happens any time the original model itself already has its own subsystems.
h_model = Simulink.findBlocks(modelName)
Simulink.BlockDiagram.createSubsystem(h_model, 'Name', 'SM_Master')
and we fixed this by changing it to
h_model = Simulink.findBlocks(modelName, Simulink.FindOptions('SearchDepth',1))
I couldn't find anything about this online, so hopefully this can help out if someone else is searching
0 Kommentare
Antworten (1)
Divyam
am 22 Nov. 2024
The call to the "findBlocks" method in the code returns the handlers for all the blocks in the model, including the ones that are already a part of a specific subsystem. The following documentation highlights the same: https://www.mathworks.com/help/simulink/slref/simulink.findblocks.html?s_tid=doc_ta#:~:text=Get%20the%20handles%20and%20names%20of%20all%20the%20blocks%20in%20a%20model.
Since your model contains additional subsystems, the blocks that are already a part of a specific subsytem cannot be a part of a second subsystem in the same level of heirarchy and hence an error is thrown when the "createSubsystem" method is called.
To summarize, this error is not a result of version upgrade to R2023a but a result of using "createSubsystem" method to create a subsystem and then creating another subsystem using the blocks that are a part of the previous subsystem in the same hierarchy.
The "Simulink.FindOptions" input argument can be passed to the "findBlocks" method in this case, to specify that the "findBlocks" method searches using a depth of "1". The "findBlocks" method then searches for all the blocks in the model but not in any of its children, this prevents the method from returning blocks that belong to pre-defined subsystems and hence the "createSubsystem" method runs without any error.
As a good practice, try to fetch the full names of the blocks returned by the "findBlocks" method, using the "getfullname" method to confirm whether the block handles returned are expected.
searchResult = Simulink.findBlocks(modelName);
fullNames = getfullname(searchResult)
To read more about the "SearchDepth" option through an example, you can refer to the following documentation: https://www.mathworks.com/help/simulink/slref/simulink.findoptions.html#:~:text=collapse%20all-,Specify%20Search%20Options,-Specify%20Search%20Options
To read more about model hierarchies and their visualization, refer to this documentation: https://www.mathworks.com/help/simulink/ug/view-model-referencing-hierarchies.html
0 Kommentare
Siehe auch
Kategorien
Mehr zu General Applications finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!