How to Use command to remove lines between physical models?

4 visualizaciones (últimos 30 días)
季
el 4 de Jun. de 2025
Comentada: el 7 de Jul. de 2025
Hi,
I want to use commands to delete this line, but 'delete_line' always results err, saying "Invalid Simulink object name: 'Battery_Cell6/1'."
Could anyone help me, pls?
  3 comentarios
季
el 9 de Jun. de 2025
Hi Sam,
yes, I want to delete the horizontal line from Battey_Cell6 to Bat+.
I suspend cursor on the ports and identified the source port of Battery_Cell6 block as LConn1 and destination port of Bat+ as RConn1. I tried to use this syntax:
add_line(gcs, 'Battery_Cell6/1', 'Bat+/1');
delete_line(gcs, 'Battery_Cell6/1', 'Bat+/1');
but get error info: Invalid Simulink object name: 'Battery_Cell6/1'.
I can only add or delete physical model line by clicking and dragging. But I want to use command in script to do it.
Many thanks!
季
el 9 de Jun. de 2025
New discovery:
If LConn1 of Battery_Cell6 and RConn1 of Bat+ is not connected to anything, I can use this syntax to add line:
add_line(gcs, 'Battery_Cell6/LConn1', 'Bat+/RConn1');
if I connect LConn1 of Battery_Cell6 with RConn1 of Battery_Cell7 manually at first, I still can use that command above to add line, but cannot use this syntax below to delete the connected line:
delete_line(gcs, 'Battery_Cell6/LConn1', 'Bat+/RConn1');
and get this error info: Invalid line specifier.

Iniciar sesión para comentar.

Respuesta aceptada

Javier Gazzarri
Javier Gazzarri el 30 de Jun. de 2025
Editada: Javier Gazzarri el 30 de Jun. de 2025
Hello 季,
I am investigating the proper way to get a proper handle to the connection line you want to delete and I'll get back to you as soon as possible. In the meantime, would you kindly try this workaround and let me know if it works for you?
Best regards,
Javier
pos = get_param(gcs+"/Bat+","Position");
ori = get_param(gcs+"/Bat+","Orientation");
delete_block(gcs+"/Bat+")
delete_line(find_system(gcs, 'FindAll', 'on', 'Type', 'line', 'Connected', 'off'))
add_block("nesl_utility/Connection Port",gcs+"/Bat+", "Position", pos, "Orientation", ori)
  1 comentario
季
el 7 de Jul. de 2025
Hi Gazzarri,
Thank you for the workaround proposed. I've tried it and it works!
Meanwhile I found another method to do it.
h = get_param(gcs+"/Bat+",'lineHandles');
delete_line(h.RConn);
To add line again with autorouting:
h2 = get_param(gcs+"/Bat+",'portHandles');
h1 = get_param(gcs+"/Battery_Cell6",'portHandles');
add_line(gcs, h1.LConn, h2.RConn, "autorouting",'on');
Best regards,
J

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programmatic Model Editing en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by