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

34 vues (au cours des 30 derniers jours)
Jeff Fetta
Jeff Fetta le 24 Mar 2017
Commenté : ciming zhu le 27 Avr 2023
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.

Réponse acceptée

Jeff Fetta
Jeff Fetta le 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

Plus de réponses (1)

Praveen Kumar
Praveen Kumar le 24 Juin 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.
  1 commentaire
ciming zhu
ciming zhu le 27 Avr 2023
Have you sloved this problem,if you did,plz tell me how did you make it,thanks a lot.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Schedule Model Components dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by