Programmatically route outports to inports

1 visualizzazione (ultimi 30 giorni)
Ramae Smith
Ramae Smith il 23 Set 2021
Commentato: Jacob Mathew il 29 Nov 2024
Hello friends,
I have a model with several hundred inports and inports connected to various subsystems. Searching for Outports and Inports with a matching name, and moving the lines around is tedious. I want to programmatically go from the first image, to the second.
At the bottom is some script I've been trying, but I'm not making progress at this point. Script and dummy model included.
%Automatically connect Outports and Inports with the same name
%Search all inports
%Replace blocks with connecting line
%Find all Outports
% a = find_system(gcs,'findall','on','SearchDepth','1','blocktype','Outport');
a = find_system(gcs,'findall','on','SearchDepth','1','blocktype','Outport')
% a=find_system(gcs, 'Selected', 'on');
% a = find_system(gcs,'Selected', 'on','blocktype','Outport');
blkp = get_param(a, 'porthandles')
% blkp = get_param(a, 'name')
dstp = blkp.Inport
%
% for i = 1:length(a)
% blkp = get_param(a(i),'porthandles');
% dstp = blkp.Inport;
% lh = get_param(dstp,'line');
% srcp = get_param(lh,'srcporthandle');
% pn = get_param(srcp,'PropagatedSignals');
%
% if ~isempty(pn)
% repn = regexprep(pn,'(^\w*) .*$','$1');
% set(a(i),'name',repn);
% end
%
% end
  1 Commento
Jacob Mathew
Jacob Mathew il 29 Nov 2024
Instead of using regular expressions, you can try to use a dictonary to keep track of inports and outports. Then connect them if they are within the same subsystem

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Modeling in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by