getSimulinkBlockHandle Inverse - Get path from handle
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
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!
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Model References 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!