getSimulinkBlockHandle Inverse - Get path from handle

7 次查看(过去 30 天)
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

采纳的回答

Anshuman
Anshuman 2023-8-1
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 个评论
Mark
Mark 2023-8-7
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Model References 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by