How to copy level 1 inport and outport blocks to top most parent level
2 ビュー (過去 30 日間)
古いコメントを表示
I need to copy level 1 inport and outport blocks to top most parent level. How to copy in/outport blocks and connect to respective input and output ports.
Please suggest.
採用された回答
TAB
2018 年 4 月 27 日
You can use following function. It works for inport block. It routes the inport block from a subsystem to route level. You can easily modify the code to make it work for outport block.
function MEditRoutePortToRootLevel(argInportH)
% Local assignment
inPBlkH = argInportH;
% Collect root model name
rootMdlH = bdroot(inPBlkH);
rootMdlName = get_param(rootMdlH, 'Name');
% Collect original inport info
inPBlkPar = get_param(inPBlkH, 'Parent');
% Loop to copy the inport block to parent level untill model root is
% reached
isParRoot = strcmp(inPBlkPar, rootMdlName);
while(~isParRoot)
% Collect inport block and its parent info
inPIdx = get_param(inPBlkH, 'Port');
inPBlkName = get_param(inPBlkH, 'Name');
inPBlkPar = get_param(inPBlkH, 'Parent');
inPBlkParH = get_param(inPBlkPar, 'handle');
inPBlkPath = [inPBlkPar '/' inPBlkName];
inPBlkParPar = get_param(inPBlkParH, 'Parent');
% Collect the corresponding port position on parent subsystem
parPortH = get_param(inPBlkParH, 'PortHandles');
pos = get_param(parPortH.Inport(str2double(inPIdx)), 'Position');
% Decide new block position
pX_OFFSET = 60;
pW = 30;
pH = 14;
pX = pos(1)- pX_OFFSET;
pY = pos(2)-(pH/2);
% Decide src and dst blocks to copy
srcBlk = inPBlkPath;
dstBlk = [inPBlkParPar '/' inPBlkName];
% Copy the inport block to subsystem parent level and add connection
newBlkH = add_block(srcBlk, dstBlk, 'Position', [pX, pY, pX+pW, pY+pH]);
add_line(inPBlkParPar, [inPBlkName '/1'], [inPBlkParSysName '/' inPIdx]);
% Check if new block is at root level. If not then loop again
inPBlkH = newBlkH;
inPBlkPar = get_param(inPBlkH, 'Parent');
isParRoot = strcmp(inPBlkPar, rootMdlName);
end
1 件のコメント
Kiran Kannan
2020 年 4 月 24 日
This works great!
'inPBlkParSysName' is undefined in code. But this can be defined as shown below in the '% Collect inport block and its parent info' section:
inPBlkParSysName = get_param(inPBlkParH, 'Name');
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Subsystems についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!