Get Simulink Block Object

20 次查看(过去 30 天)
Timo Dietz
Timo Dietz 2022-6-27
Hello,
I switched from Matlab 2020 to 2022 and now I encounter the following issue:
I need to get direct access to the objects of all blocks in a Simulink model. This way I do not need to use "get_param" for each
property of the block handle.
In 2020 it worked this way (getting all block paths, then all handle IDs of all blocks and finally calling 'handle' delivered the object):
blockList = find_system(modelName, 'RegExp', 'on'); % list of all block paths in Simulink model
handlesList = get_param(blockList,'handle'); % list of handle IDs
>> handle(handlesList{7})
ans =
Simulink.Constant
The 'handle' call in Matlab 2022 does not return the object, anymore:
>> handle(handlesList{7})
ans =
handle
In both versions, directly getting the parameter 'object' from the list of block paths works, but that does not seem to be a valid parameter - at least it's not documented:
>> objectList = get_param(blockList,'object');
>> objectList{7}
ans =
Constant with properties:
Name: 'Constant'
Is there another ('official') way of getting hands on all objects of Simulink blocks inside a model?
Thanks a lot
TD
  3 个评论
Timo Dietz
Timo Dietz 2022-6-28
编辑:Timo Dietz 2022-6-28
Not sure whether I got your question.
I'm using the returned instance for a lot of things: retrieving information, manipulating the Simulink block.
Actually, I'm reading/writing several properties like 'BackgroundColor', 'Position', 'Mask', etc. .
I know, 'get_param' and 'set_param' would work too, but for some reason these operations are remarkably slower
(at least this was the case as I started with the project some years ago with Matlab 2018).
Paul
Paul 2022-6-28
You got the question. I was unaware of that method to access the handle that way and modify block properties.
I'm surprised that set_param and get_param are remarkably slower.

请先登录,再进行评论。

回答(1 个)

Pravarthana P
Pravarthana P 2022-6-30
Hi Timo Dietz,
I can understand that you are trying to get the objects of blocks used in Simulink through “handle” function. From R2022a version we have updated the objects of Simulink which is different from the “handle” function API used in the previous versions of Simulink, so usage of “handle” not returning block objects is an expected behavior in R2022a.
We are working on the documentation regarding the new API and the function to get the block objects directly may be available in future releases.
The suggested workaround will be to use “get_param()” to get the block objects. Kindly refer to the following documentation for further details: Get parameter names and values - MATLAB get_param (mathworks.com)
Hope this information helps you!!
  1 个评论
Timo Dietz
Timo Dietz 2022-7-1
编辑:Timo Dietz 2022-7-4
Thanks for the reply.
Can you tell me whether the parameter 'object' will be valid also in future releases? Currently, it does not seem to be documented being a 'get_param()' parameter.
Sure, I could change the code and get the object by 'get_param(handle, 'object')' but it would be great to know whether that's only a workaround or a long-term solution.
Many thanks in advance,
Timo

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Model, Block, and Port Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by