How to Use command to remove lines between physical models?

4 views (last 30 days)
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 Comments
季
on 9 Jun 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!
季
on 9 Jun 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.

Sign in to comment.

Accepted Answer

Javier Gazzarri
Javier Gazzarri on 30 Jun 2025
Edited: Javier Gazzarri on 30 Jun 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 Comment
季
on 7 Jul 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

Sign in to comment.

More Answers (0)

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!