Get Simulink Block Object

23 Ansichten (letzte 30 Tage)
Timo Dietz
Timo Dietz am 27 Jun. 2022
Bearbeitet: Timo Dietz am 4 Jul. 2022
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 Kommentare
Timo Dietz
Timo Dietz am 28 Jun. 2022
Bearbeitet: Timo Dietz am 28 Jun. 2022
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 am 28 Jun. 2022
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Pravarthana P
Pravarthana P am 30 Jun. 2022
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 Kommentar
Timo Dietz
Timo Dietz am 1 Jul. 2022
Bearbeitet: Timo Dietz am 4 Jul. 2022
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Simulink Functions 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!

Translated by