Connect line using add_line command to same port connections

11 visualizaciones (últimos 30 días)
Tommy
Tommy el 1 de Abr. de 2025
Comentada: Tommy el 15 de Abr. de 2025
While I tried to collect lines in paralel, an error popup:
>> Battery_Array_tmp
Error using Battery_Array_tmp (line 33)
The first port already has a line connection
%%% connect minus to plus ports:
if v>1
add_line(mdl,PH_Add_MC_cube{v-1,i}.LConn(2),PH_Add_MC_cube{v,i}.LConn(2),'Autorouting','on');
end
Can someone assist to solve it?
I adding part of rellevant script:
%%%% Scriptto creat top design - withot Batteries/
%%%% only to speedup simulation time during debug Block connections
open_system('Battery_arc_tmp')
mdl = 'Battery_arc_tmp';
battery_model = find_system(mdl,'FindAll','on','Name','Battery_arc_tmp');
numRows = 3;
% Get handle to existing (external) POS and NEG ports
Plus_MC = find_system(mdl,'LookUnderMasks','All','FindAll','on','Name','POS');
Minus_MC = find_system(mdl,'LookUnderMasks','All','FindAll','on','Name','NEG');
%%% add MC_cube - basic String_unit:
for i=1:2 %% set two columns
colPos = 500; %% spaces between columns
for v=1:numRows %% loop for 5 String per column
nl=num2str(v + numRows*(i-1));
if i==1
% Add_MC_cube(v) = add_block('MC_Cube/STRING_MC_Cube 1', [mdl,'/STRING_MC_Cube ',nl]);
% % % % % % MC_TMP empty Submodule - only for quick compilation....
Add_MC_cube(v) = add_block('MC_TMP/STRING_MC_Cube 1', [mdl,'/STRING_MC_Cube ',nl]);
else
% Add_MC_cube(v) = add_block('MC_Cube2/STRING_MC_Cube 1', [mdl,'/STRING_MC_Cube ',nl]);
% % % % % % MC_TMP empty Submodule - only for quick compilation....
Add_MC_cube(v) = add_block('MC_TMP2/STRING_MC_Cube 1', [mdl,'/STRING_MC_Cube ',nl]);
end
posc = get(Add_MC_cube(v),'Position');
set(Add_MC_cube(v),'Position',posc + [100+(i-1)*colPos 100*(v-1)+45 100+(i-1)*colPos 100*(v-1)+45])
PH_Add_MC_cube{v,i}=get(Add_MC_cube(v),'PortHandles');
%%% connect minus to plus ports:
if v>1
add_line(mdl,PH_Add_MC_cube{v-1,i}.LConn(2),PH_Add_MC_cube{v,i}.LConn(2),'Autorouting','on');
end
end
end
while connecting 2 module there is no problem/
But when increase above 2 module i gos an error message (above)..
please, see pic attached...
Thank for assist.
Tommy
  1 comentario
Tommy
Tommy el 5 de Abr. de 2025
Editada: Tommy el 5 de Abr. de 2025
Can you assist on my last issue above? (connecting lines to same port)
Could not fined a way to solve it...
Thanks,
Tommy

Iniciar sesión para comentar.

Respuestas (1)

Altaïr
Altaïr el 14 de Abr. de 2025
Hi @Tommy,
You're on the right track. Here are a couple of points to consider from the approach being used. The current script connects only the second connection ports of blocks in a given column:
%%% connect minus to plus ports:
if v>1
add_line(mdl,PH_Add_MC_cube{v-1,i}.LConn(2),PH_Add_MC_cube{v,i}.LConn(2),'Autorouting','on');
end
To improve this, replace it with the following lines to connect the first connection ports into one group and the second connection ports into another group:
%%% connect minus and plus ports into two groups:
if v>1
add_line(mdl,PH_Add_MC_cube{v-1,i}.LConn(1),PH_Add_MC_cube{v,i}.LConn(1),'Autorouting','smart');
add_line(mdl,PH_Add_MC_cube{v-1,i}.LConn(2),PH_Add_MC_cube{v,i}.LConn(2),'Autorouting','smart');
end
Setting 'Autorouting' to smart helps in better routing of the lines. To connect these groups to the external port, simply add a connection from the external ports to the first port of each column using the lines below:
% connect the external NEG port to NEG port of STRING_MC_Cube at (ro1,col)=(1,1):
PH_Minus_MC=get(Minus_MC,'PortHandles');
add_line(mdl,PH_Minus_MC.RConn,PH_Add_MC_cube{1,1}.LConn(1), 'Autorouting','smart');
% connect the external POS port to POS port of STRING_MC_Cube at (ro1,col)=(1,2):
PH_Plus_MC=get(Plus_MC,'PortHandles');
add_line(mdl,PH_Plus_MC.RConn,PH_Add_MC_cube{1,2}.LConn(1), 'Autorouting','smart');
This approach aligns with the response to another query for consistency:
The resulting model should match expectations. I hope this meets your need!
  8 comentarios
Altaïr
Altaïr el 15 de Abr. de 2025
Editada: Altaïr el 15 de Abr. de 2025
I am unable to make the specified connection manually too, using the shared models. The issue seems to occur when 'STRING_MC_Cube 1' in 'MC_TMP' and 'MC_TMP2' is empty. Could you try running the script after filling 'STRING_MC_Cube 1' with its contents?
Tommy
Tommy el 15 de Abr. de 2025
Hi,
Great, you are right !
I just connect a simple battery (connecting + and - ports) and it works.
I wonder why connection lines are not perfect simectrical (left and right side).....;-)
preciate your help a lot
Thanks a lot

Iniciar sesión para comentar.

Categorías

Más información sobre General Applications en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by