getSimulinkBlockHandle Inverse - Get path from handle

7 Ansichten (letzte 30 Tage)
Mark
Mark am 26 Jun. 2023
Kommentiert: Mark am 7 Aug. 2023
I've recently found the the BlockPath class can provide the full address of a block, even if that block is inside a referenced model. The path from get_param(h,'Parent') will simply stop at the referenced model, but BlockPath keeps going to the root model.
This is useful, but I can't find a useful way to make a BlockPath other than with gcbp.
Is there a way to turn a handle into a BlockPath? I'm working with 2019b due to other toolchain limitations
Thanks

Akzeptierte Antwort

Anshuman
Anshuman am 1 Aug. 2023
Hi Mark, in MATLAB R2019b, there is no direct way to convert a handle into a BlockPath object. The BlockPath class was introduced in MATLAB R2020a. However, you can still achieve similar functionality by manually constructing the block path using the handle information.
Here's an example of how you can manually construct a block path given a handle in MATLAB R2019b:
% Assuming you have a handle 'h' to the block
blockPath = getfullname(h); % Get the full name of the block
% If the block is inside a referenced model, get the parent system
parentSystem = get_param(blockPath, 'Parent');
% Iterate until you reach the root model
while ~isempty(parentSystem) && ~strcmp(parentSystem, 'root')
blockPath = [get_param(parentSystem, 'Name'), '/', blockPath];
parentSystem = get_param(parentSystem, 'Parent');
end
% Display the block path
disp(blockPath);
In this example, the 'getfullname' function retrieves the full name of the block associated with the handle. Then, by iterating through the parent systems using 'get_param', you can construct the complete block path, including any referenced models, until you reach the root model.
Please note that this approach relies on the assumption that the block hierarchy is consistent with the block names and parent-child relationships. If there are multiple blocks with the same name in the model, this method might not produce the correct block path.
Hope it helps!
  1 Kommentar
Mark
Mark am 7 Aug. 2023
Many thanks,
I had implemented a similar function myself in the meantime. I just throught that there must be some functionality since gcbp was working......but it looks like not for 2019b.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Model References finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by