How to get the "data outport/Inport" already existing Blocknames from my simulink model via mscript

11 views (last 30 days)
Blocks = find_system(bdroot,'LookUnderMasks','all','BlockType','Data Outport');
I tried this code but it is not working to get the data Outport/Inport Blocknames

Answers (1)

Sameer
Sameer on 28 Mar 2024
Edited: Sameer on 28 Mar 2024
Hi Vignesh
From my understanding, you are attempting to retrieve the names of specific blocks within your Simulink model using MATLAB scripting. Specifically, you are interested in identifying blocks that serve as data inputs and outputs, which you've referred to as "data outport/inport" blocks. However, the code snippet you've provided seems not to be working as expected.
The MATLAB command you've used with find_system is almost correct but seems to have a minor issue with the 'BlockType' value for finding Data Store Read/Write or Inport/Outport blocks in a Simulink model. The 'BlockType' for Inport and Outport blocks should be 'Inport' and 'Outport', respectively, not 'Data Inport' or 'Data Outport'. If you're looking to find Data Store Read and Data Store Write blocks, their 'BlockType' values would be 'DataStoreRead' and 'DataStoreWrite', respectively.
Here's how you can correctly use find_system to get the names of ‘Inport’ and ‘Outport’ blocks from your Simulink model:
% For Outport blocks
OutportBlocks = find_system(bdroot, 'LookUnderMasks', 'all', 'BlockType', 'Outport');
% For Inport blocks
InportBlocks = find_system(bdroot, 'LookUnderMasks', 'all', 'BlockType', 'Inport');
If you are looking for Data Store Read/Write blocks, use:
% For Data Store Read blocks
DataStoreReadBlocks = find_system(bdroot, 'LookUnderMasks', 'all', 'BlockType', 'DataStoreRead');
% For Data Store Write blocks
DataStoreWriteBlocks = find_system(bdroot, 'LookUnderMasks', 'all', 'BlockType', 'DataStoreWrite');
Make sure you run these commands while your Simulink model is open. The bdroot function returns the name of the currently open Simulink model, which is used as the starting point for find_system to search for blocks. If you have multiple Simulink models open, ensure that the one you are interested in is the active window or specify the model name directly instead of using bdroot.
For example, if your model name is 'myModel', you can specify it directly:
OutportBlocks = find_system('myModel', 'LookUnderMasks', 'all', 'BlockType', 'Outport');
This will return a cell array of strings, where each string is the path to an ‘Outport’ block within your model. You can similarly replace 'Outport' with 'Inport', 'DataStoreRead', or 'DataStoreWrite' to find those specific types of blocks.
I hope this helps!
Sameer

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!