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
0 个评论
采纳的回答
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!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Model References 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!