How to retrieve the library block path once a block is created in Simulink?
35 次查看(过去 30 天)
显示 更早的评论
Hi,
I am wondering how to retrieve the library block path that we use for block creation after the element has been created.
If we want to create a new Scope Block that can be found through the model browser in the following path: 'simulink/Sinks/Scope', we execute programmatically the following in the MATLAB console:
scope = add_block('simulink/Sinks/Scope','model/ScopeName');
to get the block type we can use:
scopeBlockType = get_param(scope, 'BlockType')
% answ = 'Scope'
To my knowlege, there is no parameter we can ask to the recently created block to retrieve the original "simulink/Sinks/Scope" which is required for creation. For some use cases e.g. if we want to automate the creation extracting information from already existing blocks, this information would be indispensable.
What complicates things is that for some blocks the BlockType property does not match the name of the block on the path used for creation. For example, when we create a Stateflow Chart block, we call:
chart = add_block('sflib/Chart','model/MyChart');
which returns a different BlockType
chartBlockType = get_param(chart, 'BlockType')
% answ = 'SubSystem'
This complicates when we search for blocks of a given type, which must be specified through the use of 'BlockType' as follows:
list = find_system(model, 'BlockType', 'SubSystem');
which returns blocks that have the same 'BlockType' property but could have been created with different block signatures (e.g. 'sflib/Chart' or 'simulink/Commonly Used Blocks/Subsystem'). To my knowledge, there is no way, other than naming conventions or block-specific properties, to tell them apart or to get the signature used for creation.
I have also tried the following without any success:
libinfo(handle)
I would appreciate if you could tell me if I am missing a method or property which returns this information or to consider implementing this functionality.
0 个评论
回答(2 个)
TAB
2018-6-19
编辑:TAB
2018-6-19
Its not possible to retrieve the source of model blocks which are from built-in library.
But you can search the in the Simulink library for using properties of block used in model.
% Your block in model
scopeBlockType = get_param(scope, 'BlockType');
% To find the source, simply used find_system
open_system('simulink');
blkPaths = find_system('simulink', 'BlockType', 'Scope');
blkPaths =
'simulink/Commonly Used Blocks/Scope'
'simulink/Sinks/Floating Scope'
'simulink/Sinks/Scope'
But in my opinion this is not required.
All library block paths are always fixed. So in your automation script you can just use the table of hardcoded paths and use that table to find the source path of the block;
For example:
blkPaths = {'Inport', 'Scope'; %BlockType/Name etc
'simulink/Sources/In1', 'simulink/Sinks/Scope' %Corresponding block paths};
Robert
2020-3-5
编辑:Robert
2020-3-5
At least in the serialised form of a model (a model file) there is no history of all the editing actions that have been applied to the model in the past. So if you actually want to analyse such kind of history, you can't be helped, because it's simly not there.
This is not to be confused with a library link that consists of a reference to a subsystem in a library (And many "blocks" you will find in the simulink library are actually masked library blocks)
But if you want to do a functional analysis of the model, only block types and parameters are of interest, as they define the functional behaviour. If you want to get a list of (built-in) block types available in your version of simulink, you can use the code:
hSlLib = load_system('simulink');
hSlLibBlks = find_system(hSlLib, 'LookUnderMasks', 'all', 'Type', 'Block');
unique(get(hSlLibBlks, 'BlockType'))
(Assuming all available block types are contained at least once in simulinks standard library 'simulink').
Note that stateflow blocks are not builtin blocks, but rather S-Functions that are not easy to find out about, as with different versions of simulink they behave differently in conjunction with the simulink API. See some solutions in this thread: https://au.mathworks.com/matlabcentral/answers/156628-how-to-recognize-stateflow-blocks-using-simulink-api-get_param
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!