How do I get the x,y coordinates of port handles on a susbsytem block?

29 views (last 30 days)
How can I determine, programmatically (that is, in an M-script), the position of these port handles on a subsystem? As the subsystem resizes, or as ports are added, the "bubbled up" representation on the subsystem block changes; I want to position other elements relative to these ports and thus need to be able to determine their final positions.

Accepted Answer

Jeff Fetta
Jeff Fetta on 24 Mar 2017
Well, I answered my own question...PortConnectivity is the parameter I was looking for. Here is some code that will "clean up" the input and output ports for a subsystem like that above (assuming input and output port blocks are connected to the subsystem block). Make sure you select the subsystem to clean-up first!
% get the subsystem port handle positions
pc = get_param(gcb,'PortConnectivity');
% distance from the subsystem to the port
offset = 200;
for i = 1:numel(pc)
% position of port connector
y = pc(i).Position(2);
x = pc(i).Position(1);
% port block handle and size
if isempty(pc(i).SrcBlock)
ph = pc(i).DstBlock;
off = -(offset-50); % asthetics here...related to the width of the port block
else
ph = pc(i).SrcBlock;
off = offset;
end
% port block dimmensions
pp = get_param(ph,'Position');
w = pp(3)-pp(1);
h = pp(4)-pp(2);
% adjust position of port block
set_param(ph,'Position',[x-off,y-h/2,x-off+w,y+h-h/2]);
end

More Answers (1)

Praveen Kumar
Praveen Kumar on 24 Jun 2019
Hi,
I need help, how to backtrace the inport in between the two subsytems.
Subsystem - A is connected with Subsystem - B. I want Subsystem - B 1st inport is connected to which outport of Subsystem - A.
I need programmatically.
Anyone help me.

Categories

Find more on Schedule Model Components in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!